这篇文章主要介绍了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程序设计有所帮助。
,
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
