zl程序教程

您现在的位置是:首页 >  后端

当前栏目

php格式化日期和时间格式化示例分享

PHP日期 时间 示例 分享 格式化
2023-06-13 09:15:18 时间

复制代码代码如下:


//格式化日期
 staticfunctionformatDate($format,$datetime,$week=0){
    $datetime=$datetime>3000?$datetime:strtotime($datetime);
    if($week){
        $weeknames=[
            "日",
            "一",
            "二",
            "三",
            "四",
            "五",
            "六"
        ];
        $format=str_replace("w",$weeknames[date("w",$datetime)],$format);
    }
    returndate($format,$datetime);
 }

复制代码代码如下:


echo"周".formatDate("w","2012-11-0300:46:22",1)."".formatDate("Y-m-d","2012-11-0300:46:22");
echo"周".formatDate("w","1388678400",1)."".formatDate("Y-m-d","1388678400");

周六2012-11-03
周五2014-01-03