本文共 1012 字,大约阅读时间需要 3 分钟。
/** * @param $month * @return string * 指定年月份获取月初月末的时间戳 */ public function getTime($month) { $month_start = strtotime($month);//指定年月份月初时间戳 $BeginDate = date('Y-m-01', strtotime($month)); $EndDate = date('Y-m-d', strtotime("$BeginDate +1 month -1 day")); $month_end = strtotime("next day", strtotime($EndDate)) - 1;//指定年月份月末时间戳 $months = $month_start . ' and ' . $month_end; return $months; }
获取从2017-01到现在所有的月份
$start_time = "2017-01"; $strtotime_start_time = strtotime($start_time); $lastMonth = strtotime(date("Y-m", time())); $monthArr = []; for ($i = 1; $lastMonth > $strtotime_start_time; $i++) { $lastMonths = strtotime(date('Y-m') . '-01 00:00:01'); $t = "-". $i ." month"; $lastMonths = date('Y-m', strtotime($t, $lastMonths)); var_dump(strtotime($lastMonths)); array_push($monthArr, $lastMonths); $lastMonth = strtotime($lastMonths); }
转载地址:http://qqtnn.baihongyu.com/