Timezone conversion to a specific timezone helps to synchronize different DateTime. It is very useful to balance the server time and the user’s local time. PHP DateTime class provides an easy way to convert a date time stamp to UTC. You can convert any timezone to UTC DateTime using PHP.
In the example code snippet, we will show you how to convert local Date & Time to UTC DateTime (YYYY-MM-DD HH:MM:SS format) in PHP.
Convert Current DateTime to UTC DateTime using PHP:
$dateTime = date("Y-m-d H:i:s");
$newDateTime = new DateTime($dateTime);
$newDateTime->setTimezone(new DateTimeZone("UTC"));
$dateTimeUTC = $newDateTime->format("Y-m-d H:i:s");
Convert Local DateTime to UTC DateTime using PHP:
$dateTime = '2021-04-28 18:37:54';
$tz_from = 'America/New_York';
$newDateTime = new DateTime($dateTime, new DateTimeZone($tz_from));
$newDateTime->setTimezone(new DateTimeZone("UTC"));
$dateTimeUTC = $newDateTime->format("Y-m-d H:i:s");
Great articles. You have created useful blogs and I am learning PHP by using your blogs.
I have bookmarked your page. Thank you and keep writing.