-1
$utc_date = '2020-07-31T00:00:00.000Z';

Now i want this date in yyyy-mm-dd hh:mm:ss format like (2020-07-31 00:00:00), So can we achieve in PHP? How can we do it in easiest way?

  • 1
    Does this answer your question? [How can I easily convert dates from UTC via PHP?](https://stackoverflow.com/questions/952975/how-can-i-easily-convert-dates-from-utc-via-php) – Always Helping Jul 31 '20 at 09:53

1 Answers1

1

Like this.

$utc_date = '2020-07-31T00:00:00.000Z';
$jsDateTS = strtotime($utc_date);
if ($jsDateTS !== false) 
    echo date('Y-m-d H:i:s', $jsDateTS );

Edit: Changed code to include timezone change.

$utc_date = '2020-07-31T00:00:00.000Z';
$timestamp = strtotime($utc_date);
$date = new DateTime();
$date->setTimestamp($timestamp);
$date->setTimezone(new \DateTimeZone('America/Los_Angeles'));
echo $date->format('Y-m-d H:i:s') . "\n";

Working Example.

Umair Khan
  • 1,684
  • 18
  • 34