Skip to content

Instantly share code, notes, and snippets.

@Jason-cqtan
Created September 29, 2019 08:40
Show Gist options
  • Save Jason-cqtan/394f30ee2c76b539635d973d3525d92c to your computer and use it in GitHub Desktop.
Save Jason-cqtan/394f30ee2c76b539635d973d3525d92c to your computer and use it in GitHub Desktop.
获取指定月份列表时间
/**
* 获取指定月份列表时间
* @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