Created
September 29, 2019 08:40
-
-
Save Jason-cqtan/394f30ee2c76b539635d973d3525d92c to your computer and use it in GitHub Desktop.
获取指定月份列表时间
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取指定月份列表时间 | |
* @param $year int 哪年 | |
* @param $start_month int 起止月份 | |
* @param $end_month int 截止月份 | |
* @return array | |
*/ | |
protected function getMonths($year, $start_month, $end_month) | |
{ | |
$month = []; | |
$month_map = [ | |
1 => 31, | |
2 => ($year % 4) === 0 ? 28 : 29, | |
3 => 31, | |
4 => 30, | |
5 => 31, | |
6 => 30, | |
7 => 31, | |
8 => 31, | |
9 => 30, | |
10 => 31, | |
11 => 30, | |
12 => 31 | |
]; | |
for ($i = $start_month; $i <= $end_month; $i++) | |
{ | |
$currMonth = $i < 10 ? "0{$i}" : $i; | |
$month[] = [ | |
'start' => strtotime("{$year}-{$currMonth}-01 00:00:00"), | |
'end' => strtotime("{$year}-{$currMonth}-{$month_map[$i]} 23:59:59") | |
]; | |
} | |
return $month; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment