首页 > 开发 > Php > 正文

php强大的时间转换函数strtotime

2020-02-21 20:43:51
字体:
来源:转载
供稿:网友

使用strtotime可以将各种格式的时间字符串转换为时间戳

转换常规时间格式

echo date('Y-m-d H:i:s', strtotime('2016-01-30 18:00')).PHP_EOL;echo date('Y-m-d H:i:s', strtotime('20160130180001')).PHP_EOL; 

转换自然时间描述

//昨天echo date('Y-m-d H:i:s', strtotime('yesterday')).PHP_EOL;//上周echo date('Y-m-d H:i:s', strtotime('last week')).PHP_EOL;//本周开始时间echo date('Y-m-d H:i:s', strtotime('this week midnight')).PHP_EOL;//本月开始时间echo date('Y-m-d H:i:s', strtotime('first day of this month midnight')).PHP_EOL; //计算相对时间echo date('Y-m-d H:i:s', strtotime('+1 month')).PHP_EOL;

完整的php时间描述文档可以参考 http://php.net/manual/zh/datetime.formats.relative.php

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表