donglizuo8892 2015-06-23 06:07
浏览 45
已采纳

不希望的自动递增分钟

The Code:

$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);

The Undesired output:

// 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 Desired output:

// 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
)

The problem: I don't know why the minutes gets also incremented when I statically put it as midnight. Any help would be appreciated thanks.

  • 写回答

1条回答 默认 最新

  • dongtu1789 2015-06-23 06:10
    关注

    Cause You were incrementing month with each loop H:m:s which should be H:i:s

    Within php date function m stands for month and i for minutes

    $date_ranges_from[] = date('F d, Y H:m:s', strtotime("$month 1 midnight"));
                                      //^^ m stands for month
    

    should be

    $date_ranges_from[] = date('F d, Y H:i:s', strtotime("$month 1 midnight"));
                                      //^^ i stands for minutes
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大