码迷,mamicode.com
首页 > Web开发 > 详细

php date strtotime的用法

时间:2017-06-05 16:43:08      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:begin   time   时间   php   ret   pre   div   turn   blog   

1.上个月第一天及最后一天.
   echo date(‘Y-m-01‘, strtotime(‘-1 month‘));

   echo strtotime(date(‘Y-m-01 0:00:00‘, strtotime(‘-1 month‘)));  //月初第一天时间戳
   echo "<br/>";
   echo date(‘Y-m-t‘, strtotime(‘-1 month‘));
   echo "<br/>";
2.获取当月第一天及最后一天.
   $BeginDate=date(‘Y-m-01‘, strtotime(date("Y-m-d")));
   echo $BeginDate;
   echo "<br/>";
   echo date(‘Y-m-d‘, strtotime("$BeginDate +1 month -1 day"));
   echo "<br/>";
3.获取当天年份、月份、日及天数.
   echo " 本月共有:".date("t")."天";
   echo " 当前年份".date(‘Y‘);
   echo " 当前月份".date(‘m‘);
   echo " 当前几号".date(‘d‘);
   echo "<br/>";
4. 获取当月第一天及最后一天 
   function getthemonth($date)
   {
   $firstday = date(‘Y-m-01‘, strtotime($date));
   $lastday = date(‘Y-m-t‘, strtotime($date));
   return array($firstday,$lastday);
   }
   $today = date("Y-m-d");
   $day=getthemonth($today);
   echo "当月的第一天: ".$day[0]." 当月的最后一天: ".$day[1];
   echo "<br/>";

 

php date strtotime的用法

标签:begin   time   时间   php   ret   pre   div   turn   blog   

原文地址:http://www.cnblogs.com/wuheng1991/p/6945382.html

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