php格式化日期实例分析
本文实例讲述了php格式化日期的方法。分享给大家供大家参考。
具体实现代码如下:
代码如下:
function ShowDate($flag=0, $timestr=NULL) { // 获取周几 $warr = array( "0" => 星期日, "1" => 星期一, "2" => 星期二, "3" => 星期三, "4" => 星期四, "5" => 星期五, "6" => 星期六 ); $i = date("w", $timeStamp); // 设置北京时间并获取时间戳 date_default_timezone_set('PRC'); $timeStamp = NULL; if ($timestr) $timeStamp = strtotime($timestr); else $timeStamp = time(); // 设置时间显示格式 $ret1 = date("Y年m月d日 H:m:s", $timeStamp) . " " . $warr[$i]; $ret2 = date("Y-m-d H:m:s", $timeStamp) . " " . $warr[$i]; $ret3 = date("y/m/d", $timeStamp); $ret = $ret1; // 默认返回第一种 if ($flag == 2) $ret = $ret2; else if ($flag == 3) $ret = $ret3; return $ret; }
希望本文所述对大家的PHP程序设计有所帮助。
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23