Using PHP
It’s really simple to convert a DateTime
from one time zone to another in PHP. Just create a DateTime
object using date & time to be converted as the first parameter and the original time zone as the second parameter. Then change the time zone to the desired one using the setTimezone
method. That’s all!
$date = new DateTime('2022-02-01 12:10:33', new DateTimeZone('Europe/London')); echo $date->format('Y-m-d H:i:sP') . "\n"; $date->setTimezone(new DateTimeZone('Europe/Bucharest')); echo $date->format('Y-m-d H:i:sP') . "\n";
The above will output:
2022-02-01 12:10:33+01:00 2022-02-01 14:10:33+03:00
Using JavaScript
<script type="text/javascript"> let date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); console.log('Given IST datetime: ' + date.toLocaleString()); let usaTime = date.toLocaleString("en-US", {timeZone: "America/New_York"}); console.log('USA datetime: ' + usaTime); </script>
Result:
2022-02-01 12:10:33+01:00