drb0901500211 2014-01-07 10:17
浏览 6

更改时间格式[关闭]

sorry for my English. I’m trying this:

$startTime = strtotime('2013-12-23');
$endTime = strtotime('2013-12-31');

for ($i = $startTime; $i <= $endTime; $i = $i + 86400) {

    echo date('m.d.Y', $i)."<br/>";

    echo date('d-m-Y', strtotime(date('m.d.Y', $i)))."<br />";

}

So, why I get:

12.23.2013
01-01-1970
12.24.2013
01-01-1970
...

If I try

echo date('m.d.Y', $i)."<br/>";
echo date('d-m-Y', $i)."<br/>";

It’s ok, I get correct result.

Thanks You.

  • 写回答

2条回答 默认 最新

  • douzhankui0758 2014-01-07 10:19
    关注

    The m.d.Y is a format strtotime can not parse. Use another format ( eg 'c' ) to get it working.

    This is from the php manual

    Note: Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.

    评论

报告相同问题?

悬赏问题

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