Zak Zak - 24 days ago 6
PHP Question

Get time in other cities given a city to start

Suppose I have a given city (eg. Milan) with a given time (which I write), and I need to know the time in other city (suppose New York and Tokyo), how can I accomplish this in code (the cities will be always the same, so... an array)?

Answer
$ts = new DateTime('2016-11-17 11:39:00', new DateTimeZone('Europe/London'));
$ts->setTimezone(new DateTimeZone('America/New_York'));

echo $ts->format('Y-m-d H:i:s');

That's all you need to do. You just need to make sure you're using one of the defined timezones. If you have any cities not in this list, you need to map them to the appropriate timezone they're in, like Milan → Europe/Rome.