Reputation: 21
If i have date can I add different timezone?
e.g. i have 1/1/2000 5pm in +2gmt i need to add +4gmt = 1/1/2000 7pm
or substract -6gmt from thjis so i will get 1pm?
Upvotes: 2
Views: 150
Reputation: 24969
You could use DateTime
and DateTimeZone
. There's also a DateInterval
class that allows you to specify an interval that you can use with DateTime::add
and DateTime::sub
.
<?php
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . PHP_EOL;
$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP') . PHP_EOL;
?>
Outputs:
2000-01-01 00:00:00+12:00
2000-01-01 01:45:00+13:45
Upvotes: 3