您的位置:首页 > 编程语言 > PHP开发

PHP 时间格式

2016-03-17 10:38 295 查看

在PHP  函数date  格式很多 重在形式

 

echo date('Y-m-d H:i:s', time());

 

输出的时间是: 2016-03-17 10:31:38

 

常用的一些对应的系统函数

字符串转换成时间戳:

strtotime

date()

然后就是一些活用的方法

echo date("Y-m-d");

// 昨天
echo date("Y-m-d",strtotime("-1 day"));
// 明天
echo date("Y-m-d",strtotime("+1 day"));
// 一周后
echo date("Y-m-d",strtotime("+1 week"));
// 一周零两天四小时两秒后
echo ":".date("Y-m-d H:i:s",strtotime("+1 week 2 days 4 hours 2 seconds"));
// 下个星期四
echo date("Y-m-d",strtotime("next Thursday"));
// 上个周一
echo date("Y-m-d",strtotime("last Monday");
// 一个月前
echo date("Y-m-d",strtotime("last month");
// 一个月后
echo date("Y-m-d",strtotime("+1 month");
// 十年后
echo date("Y-m-d",strtotime("+10 year");

更多的,要自己去写了,我就不举例哈

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: