Translating a date from one time zone to another
How do I translate a date from one time zone to another?
Given the date 2015-09-14 10:29:01
, in the time zone Europe/London
You want to convert it to a date but in the time zone Europe/Moscow
How can I do this using the standard methods php
?
+If there are functions for checking the existence of a time zone in the database php
1
Author: Denis Kotlyarov, 2015-10-16
1 answers
The DateTime
class has a function SetTimezone
(docks)
I.e. you will have something like this:
$date = new DateTime('2015-09-14 10:29:01', new DateTimeZone('Europe/London'));
echo $date->format('Y-m-d H:i:sP') . '<br>';
$date->setTimezone(new DateTimeZone('Europe/Moscow'));
echo $date->format('Y-m-d H:i:sP');
Will output
2015-09-14 10:29:01+01:00
2015-09-14 13:29:01+04:00
5
Author: cyadvert, 2015-10-16 19:18:05