当前位置:首页 > PHP教程 > PHP高级教程

php强大的时间转换函数strtotime

使用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



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!