NOW() function in PHP

2020-01-25 12:22发布

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(), but I am asking if there is a function only for this.

For example, to return:

2009-12-01 00:00:00

16条回答
Summer. ? 凉城
2楼-- · 2020-01-25 12:49

Try this:

date("Y-m-d H:i:s");
查看更多
叛逆
3楼-- · 2020-01-25 12:49

Use strftime:

strftime("%F %T");
  • %F is the same as %Y-%m-%d.

  • %T is the same as %H:%M:%S.

Here's a demo on ideone.

查看更多
贼婆χ
4楼-- · 2020-01-25 12:57

You can use the PHP date function with the correct format as the parameter,

echo date("Y-m-d H:i:s");
查看更多
Lonely孤独者°
5楼-- · 2020-01-25 13:01

MySQL function NOW() returns the current timestamp. The only way I found for PHP is using the following code.

$curr_timestamp = date('Y-m-d H:i:s');
查看更多
登录 后发表回答