当前位置: 移动技术网 > IT编程>开发语言>PHP > php强大的时间转换函数strtotime

php强大的时间转换函数strtotime

2017年12月12日  | 移动技术网IT编程  | 我要评论

使用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时间描述文档可以参考

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网