如何获取日期时间格式PHP的当前时间? [重复]

This question already has an answer here:

I need to get current time in UTC to store in in datetime field(2019-08-17 00:00:00) type in MySQL.

How to get it in PHP?

I tried: now(); it gives me milliseconds

</div>

You should find info about the DateTime class to work with dates in php

$d = new DateTime('now');
$d->setTimezone(new DateTimeZone('UTC'));
echo $d->format('Y-m-d H:i:s');

You should try this.

date_default_timezone_set('UTC');
echo date('Y-m-d H:i:s');
// Output will be : 2019-08-16 09:41:24

try this code

$date=date_create(date("Y-m-d h:i:s"));
echo date_format($date,"Y-m-d H:i:s");
#output : 2019-08-16 09:49:20