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

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

Which PHP function can return the current date/time?

30条回答
  •  无人共我
    2020-11-22 08:47

    PHP's time() returns a current Unix timestamp. With this, you can use the date() function to format it to your needs.

    $date = date('Format String', time());
    

    As Paolo mentioned in the comments, the second argument is redundant. The following snippet is equivalent to the one above:

    $date = date('Format String');
    

提交回复
热议问题