码迷,mamicode.com
首页 > 其他好文 > 详细

获取一个想要的日期,时间

时间:2017-11-17 13:28:59      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:应该   div   style   time   strtotime   时间戳   std   日期时间   rda   

  很重要的函数: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.如果有两个参数,则第二个参数应该是时间戳格式;

获取一个想要的日期,时间

标签:应该   div   style   time   strtotime   时间戳   std   日期时间   rda   

原文地址:http://www.cnblogs.com/wxdblog/p/7850949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!