我是靠谱客的博主 鲤鱼奇异果,这篇文章主要介绍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

最后

以上就是鲤鱼奇异果最近收集整理的关于php强大的时间转换函数strtotime的全部内容,更多相关php强大内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(149)

评论列表共有 0 条评论

立即
投稿
返回
顶部