I have these timezones. I want to get the current datetime depends on the given timezone. The user will select either one timezone. so need to return current time.
ASKT
CDT
EDT
HST
MDT
MST
PDT
How can i convert? Please help
Use the DateTime
Class
$time = time(); //Get the current time
$date = new DateTime($time, new DateTimeZone('Pacific/Nauru')); //Set a time zone
echo $date->format('Y-m-d H:i:sP') . "
"; //display date
$date->setTimezone(new DateTimeZone('Europe/London')); //set another timezone
echo $date->format('Y-m-d H:i:sP') . "
"; //display data again
This, way you don't have to give the same timestamp as new argument every time like mishu's answer.
DateTime::setTimezone would help you.
<?php
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "
";
$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP') . "
";
?>
See the class written by "the_dark_lord12001 at yahoo dot com" this will help you to get timezones from abbreviations & then you can use it with either date_default_timezone_set or DateTime class
http://www.php.net/manual/en/datetimezone.listabbreviations.php
Hope this help.
~K