获取一个想要的日期,时间
Posted 微醺
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取一个想要的日期,时间相关的知识,希望对你有一定的参考价值。
很重要的函数:strtotime()
比如获取某个时间一周前日期应该是什么?
1 //当前时间 2 $nowDate = "2017-01-01 00:00:00"; 3 $lastWeek = date(‘Y-m-d H:i:s‘ , strtotime(‘-1 week ‘, strtotime($nowDate))); 4 echo ‘上周的日期时间为:‘.$lastWeek;
获取一天前,一月前,一年前方法也是如此
//1天前 $lastDayDate = date("Y-m-d H:i:s", strtotime(‘-1 day‘, strtotime($dtE))); //1月前 $lastMonthDate = date("Y-m-d H:i:s", strtotime(‘-1 month‘, strtotime($dtE))); //1年前 $lastYearDate = date("Y-m-d H:i:s", strtotime(‘-1 year‘, strtotime($dtE)));
注意:strtotime()函数,
1.如果只有一个参数,即获取某个日期的时间戳;
2.如果有两个参数,则第二个参数应该是时间戳格式;
以上是关于获取一个想要的日期,时间的主要内容,如果未能解决你的问题,请参考以下文章