本文介绍下,用php获取本周、本月第一天与最后天时间戳的代码,有需要的朋友作个参考。
用php获取本周、本月第一天与最后天时间戳。 1,获取今天的时间范围: <?php $start = mktime(0,0,0,date("m"),date("d"),date("Y")); $end = mktime(0,0,0,date("m"),date("d")+1,date("Y")); 2,获取本周第一天/最后一天的时间戳 <?php $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); } 3,获取本月第一天/最后一天的时间戳 <?php $year = date("Y"); $month = date("m"); $allday = date("t"); $strat_time = strtotime($year."-".$month."-1"); $end_time = strtotime($year."-".$month."-".$allday); |