首頁 >後端開發 >php教程 >PHP获取本周本月第一天、最后一天时间戳的代码

PHP获取本周本月第一天、最后一天时间戳的代码

WBOY
WBOY原創
2016-06-20 13:03:251105瀏覽

获取本周第一天/最后一天的时间戳

 $year = date("Y");
 $month = date("m");
 $day = date('w');
 $nowMonthDay = date("t");

 $firstday = date('d') - $day;
 if(substr($firstday,0,1) == "-"){
  $firstMonth = $month - 1;
  $lastMonthDay = date("t",$firstMonth);
  $firstday = $lastMonthDay - substr($firstday,1);
  $time_1 = strtotime($year."-".$firstMonth."-".$firstday);
 }else{
  $time_1 = strtotime($year."-".$month."-".$firstday);
 }
   
 $lastday = date('d') + (7 - $day);
 if($lastday > $nowMonthDay){
  $lastday = $lastday - $nowMonthDay;
  $lastMonth = $month + 1;
  $time_2 = strtotime($year."-".$lastMonth."-".$lastday);
 }else{
  $time_2 = strtotime($year."-".$month."-".$lastday);
 }


 
获取本月第一天/最后一天的时间戳
 

 $year = date("Y");
 $month = date("m");
 $allday = date("t");
 $strat_time = strtotime($year."-".$month."-1");
 $end_time = strtotime($year."-".$month."-".$allday);

 


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn