How do I get the current date and time in PHP?

后端 未结 30 1654
孤城傲影
孤城傲影 2020-11-22 08:19

Which PHP function can return the current date/time?

30条回答
  •  灰色年华
    2020-11-22 09:11

    Another simple way is to take the timestamp of the current date and time. Use mktime() function:

    $now = mktime(); // Return timestamp of the current time
    

    Then you can convert this to another date format:

    //// Prints something like: Thursday 26th of January 2017 01:12:36 PM
    echo date('l jS \of F Y h:i:s A',$now);
    

    More date formats are here: http://php.net/manual/en/function.date.php

提交回复
热议问题