守则:
$months = array("January", "February" .......); // Up to December
foreach ($months As $month) {
$date_ranges_from[] = date('F d, Y H:m:s', strtotime("$month 1 midnight"));
}
print_r($date_ranges_from);
不受欢迎的输出:
// Notice that the minutes are auto-incremented
Array
(
[0] => January 01, 2015 00:01:00
[1] => February 01, 2015 00:02:00
[2] => March 01, 2015 00:03:00
[3] => April 01, 2015 00:04:00
[4] => May 01, 2015 00:05:00
[5] => June 01, 2015 00:06:00
[6] => July 01, 2015 00:07:00
[7] => August 01, 2015 00:08:00
[8] => September 01, 2015 00:09:00
[9] => October 01, 2015 00:10:00
[10] => November 01, 2015 00:11:00
[11] => December 01, 2015 00:12:00
)
所需的输出:
// The time should always be 00:00:00
Array
(
[0] => January 01, 2015 00:00:00
[1] => February 01, 2015 00:00:00
[2] => March 01, 2015 00:00:00
[3] => April 01, 2015 00:00:00
[4] => May 01, 2015 00:00:00
[5] => June 01, 2015 00:00:00
[6] => July 01, 2015 00:00:00
[7] => August 01, 2015 00:00:00
[8] => September 01, 2015 00:00:00
[9] => October 01, 2015 00:00:00
[10] => November 01, 2015 00:00:00
[11] => December 01, 2015 00:00:00
)
问题: 当我静静地把它作为午夜时,我不知道为什么分钟也会增加。任何帮助将不胜感激。
答案 0 :(得分:1)
原因您每个循环H:m:s
应增加月份H:i:s
在php date
内,m
代表month
代表i
和minutes
代表$date_ranges_from[] = date('F d, Y H:m:s', strtotime("$month 1 midnight"));
//^^ m stands for month
$date_ranges_from[] = date('F d, Y H:i:s', strtotime("$month 1 midnight"));
//^^ i stands for minutes
应该是
{{1}}