Set time in php to 00:00:00

后端 未结 4 711
名媛妹妹
名媛妹妹 2021-02-08 10:40

I need to display the time but it must start from 00:00:00? I\'ve got the following but it uses the current time.

print(date(\"H:i:s\"));
4条回答
  •  失恋的感觉
    2021-02-08 11:24

    As an alternative to mktime(), try the newer DateTime class, eg

    $dt = new DateTime;
    $dt->setTime(0, 0);
    echo $dt->format('H:i:s');
    
    // Add one hour
    $dt->add(new DateInterval('PT1H'));
    echo $dt->format('H:i:s');
    

    Update

    The flexibility of DateInterval makes this a very good candidate for a timer, eg

    // add 2 years, 1 day and 9 seconds
    $dt->add(new DateInterval('P2Y1DT9S'));
    

提交回复
热议问题