ホームページ  >  記事  >  バックエンド開発  >  今週と今月の最初と最後の日のタイムスタンプを取得する PHP コード

今週と今月の最初と最後の日のタイムスタンプを取得する PHP コード

WBOY
WBOYオリジナル
2016-06-20 13:03:251033ブラウズ

週の最初/最後の日のタイムスタンプを取得します

 $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 までご連絡ください。