Set time in php to 00:00:00

后端 未结 4 714
名媛妹妹
名媛妹妹 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:29

    Use mktime() if you want to start with midnight for the current date:

    
    

    OUTPUTS

    Friday 14th of October 2011 12:00:00 AM
    

    http://codepad.org/s2NrVfRq

    In mktime(), you pass arguments for hours, minutes, seconds, month, day, year, so set hours, minutes, seconds to 0 to get today at midnight. (Note, as Phil points out, mktime()'s arguments are optional and you can leave month, day, year out and it will default to the current date).

    The mktime() function returns a unix timestamp representing the number of seconds since the unix epoch (January 1, 1970). You can count up from it in seconds or multiples of seconds.

    
    

    OUTPUTS

    Friday 14th of October 2011 12:00:00 AM
    Friday 14th of October 2011 12:01:00 AM
    Friday 14th of October 2011 01:00:00 AM
    

    http://codepad.org/FTr98z1n

提交回复
热议问题