php 时间函数strtotime 使用详解

定义和用法 strtotime()
strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。

语法
strtotime(time,now)

参数描述
time规定要解析的时间字符串。
now用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
     // #1echo strtotime("now");  // 获取当前时间戳echo date('Y-m-d H:i:s', strtotime("now"));// #2echo strtotime("2015-06-11 10:11:00");  // 获取指定的时间戳echo date('Y-m-d H:i:s', strtotime("2015-06-11 10:11:00"));// #3echo strtotime("3 October 2005");   // 获取指定的时间戳[等同于strtotime("2005-10-03")]echo date('Y-m-d H:i:s', strtotime("3 October 2005"));// #4echo strtotime("+5 hours"); // 当前时间加五个小时 [对比#1]echo date('Y-m-d H:i:s', strtotime("+5 hours"));// #5echo strtotime("+1 day");   // 当前时间加1天 [对比#1]echo date('Y-m-d H:i:s', strtotime("+1 day"));// #6echo strtotime("+2 days");  // 当前时间加多天 名词变复数 [对比#1]echo date('Y-m-d H:i:s', strtotime("+2 days"));// #7echo 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"));// #8echo strtotime("next Monday");  // 当前时间下一个周一echo date('Y-m-d H:i:s', strtotime("next Monday"));// #9echo strtotime("last Sunday");  // 当前时间前一个周日echo date('Y-m-d H:i:s', strtotime("last Sunday"));// #10echo 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")));// #11echo 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')));


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部