Jo Smo Jo Smo - 10 days ago 8
PHP Question

How to convert a datetime string to UTC string?

I have a datetime string like this:

`2012-09-03 22:00 Central USA Time`.


and i want to convert it to the UTC time zone.

Answer

Use gmdate() and strtotime() :

date_default_timezone_set('America/New_York');
echo gmdate('Y-m-d H:i', strtotime('2012-09-03 22:00'));

Instead of Central USA Time, use the supported timezones : http://www.php.net/manual/en/timezones.php

The date_default_timezone_get() function will always give you the right timezone

Comments