代码之家  ›  专栏  ›  技术社区  ›  Nrc

PHP时间,包括第一天

  •  0
  • Nrc  · 技术社区  · 7 年前

    我在MySql数据库中有一个时间戳。格式为:2018-08-28 12:39:59

    $begin = strtotime("first day of this month midnight");
    $begin = date("Y-m-d h:i:s", $begin);
    

    如果我回音$begin给我:2018-08-01 12:00:00

    我一直在搜索,官方文件上说:

    http://php.net/manual/en/datetime.formats.relative.php

    2 回复  |  直到 7 年前
        1
  •  1
  •   Javier Larroulet    7 年前

    PHP的date函数有两个不同的修饰符:H和H

    尝试

    $begin = date("Y-m-d H:i:s", $begin);
    

    将按预期输出00:00:00

        2
  •  1
  •   AymDev    7 年前

    您使用了错误的小时格式,应执行以下操作:

    //     uppercase H --v
    $begin = date("Y-m-d H:i:s", $begin);
    
    // Output: 2018-08-01 00:00:00
    echo $begin;
    

    documentation

    • h :带前导零的一小时的12小时格式
    • H