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

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

Which PHP function can return the current date/time?

30条回答
  •  忘了有多久
    2020-11-22 08:57

    According to the article How to Get Current Datetime (NOW) with PHP, there are two common ways to get the current date. To get current datetime (now) with PHP, you can use the date class with any PHP version, or better the datetime class with PHP >= 5.2.

    Various date format expressions are available here.

    Example using date

    This expression will return NOW in format Y-m-d H:i:s.

    
    

    Example using datetime class

    This expression will return NOW in format Y-m-d H:i:s.

    format('Y-m-d H:i:s');
    ?>
    

提交回复
热议问题