NOW() function in PHP

前端 未结 20 1655
遥遥无期
遥遥无期 2020-11-28 17:26

Is there a PHP function that returns the date and time in the same format as the MySQL function NOW()?

I know how to do it using date(), b

20条回答
  •  孤城傲影
    2020-11-28 17:44

    There is no built-in PHP now() function, but you can do it using date().

    Example

    function now() {
        return date('Y-m-d H:i:s');
    }
    

    You can use date_default_timezone_set() if you need to change timezone.

    Otherwise you can make use of Carbon - A simple PHP API extension for DateTime.

提交回复
热议问题