php时间函数strtotime使用详解
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php时间函数strtotime使用详解,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2420字,纯文字阅读大概需要4分钟。
内容图文
![php时间函数strtotime使用详解](/upload/InfoBanner/zyjiaocheng/138/32ef6439c14e44c5a544947734aaac46.jpg)
定义和用法 strtotime()
strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。语法
strtotime(time,now)
参数 | 描述 |
---|---|
time | 规定要解析的时间字符串。 |
now | 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。 |
说明
该函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数,则用系统当前时间。
该函数将使用 TZ 环境变量(如果有的话)来计算时间戳。自 PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在 date_default_timezone_get() 函数页面中有说明。
// #1 echo strtotime("now"); // 获取当前时间戳 echo date('Y-m-d H:i:s', strtotime("now")); // #2 echo strtotime("2015-06-11 10:11:00"); // 获取指定的时间戳 echo date('Y-m-d H:i:s', strtotime("2015-06-11 10:11:00")); // #3 echo strtotime("3 October 2005"); // 获取指定的时间戳[等同于strtotime("2005-10-03")] echo date('Y-m-d H:i:s', strtotime("3 October 2005")); // #4 echo strtotime("+5 hours"); // 当前时间加五个小时 [对比#1] echo date('Y-m-d H:i:s', strtotime("+5 hours")); // #5 echo strtotime("+1 day"); // 当前时间加1天 [对比#1] echo date('Y-m-d H:i:s', strtotime("+1 day")); // #6 echo strtotime("+2 days"); // 当前时间加多天 名词变复数 [对比#1] echo date('Y-m-d H:i:s', strtotime("+2 days")); // #7 echo strtotime("+1 week 3 days 7 hours 5 seconds"); // 当前时间加 1周 3天 7小时 5秒 [对比#1] echo date('Y-m-d H:i:s', strtotime("+1 week 3 days 7 hours 5 seconds")); // #8 echo strtotime("next Monday"); // 当前时间下一个周一 echo date('Y-m-d H:i:s', strtotime("next Monday")); // #9 echo strtotime("last Sunday"); // 当前时间前一个周日 echo date('Y-m-d H:i:s', strtotime("last Sunday")); // #10 echo strtotime("-1 day",strtotime("2018-07-01 10:11:00")); // 给定时间 减去一天 echo date('Y-m-d H:i:s', strtotime("-1 day",strtotime("2018-07-01 10:11:00")));
时间名词:
年year 复数years
月month 复数months
周week 复数weeks
日day 复数days
时hour 复数hours
分second 复数seconds
秒minute 复数minutes
上一个last
下一个next
一月January
二月February
三月March
四月April
五月May
六月June
七月July
八月August
九月September
十月October
十一月November
十二月December
相关推荐:
php 使用strtotime获取上个月、下个月、本月的日期代码实例
php中strtotime函数详解
以上就是php 时间函数strtotime 使用详解的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的php时间函数strtotime使用详解全部内容,希望文章能够帮你解决php时间函数strtotime使用详解所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。