In PHP Date Time Zone class displays the time of different time zone, along with time it is also capable of displaying the longitude, latitude and comment (if any) of the country.
Example:
<?php
//To instantiate an object$time=new DateTimeZone("Asia/kolkata"); echo("<b>Few Important functions of DateTimeZone are given below</b><br/>"); echo("<b>To know the location:</b><br/>");
print_r(
$time->getLocation()); echo "<br/><b>To get the name of the timezone</b><br/>";print_r(
$time->getName()); echo"<br/><b>To get all transition for the timezone</b><br/>";print_r(reset(
$time->getTransitions())); echo"<br/><b>To know the containing dst, offset, and timezone name in the form of associative array</b><br/>"; $timez=DateTimeZone::listAbbreviations();print_r(
$timez["acst"]);?>
Output:
Few Important functions of DateTimeZone are given below
To know the location:
Array ( [country_code] => IN [latitude] => 22.53333 [longitude] =>
88.36666 [comments] => )
To get the name of the timezone
Asia/kolkata
To get all transition for the timezone
Array ( [ts] => -2147483648 [time] => 1901-12-13T20:45:52+0000 [offset]
=> 21200 [isdst] => [abbr] => HMT )
To know the containing dst, offset, and timezone name in the form of
associative array
Array ( [0] => Array ( [dst] => 1 [offset] => -14400 [timezone_id]
=> America/Porto_Acre ) [1] => Array ( [dst] => 1 [offset] => -14400
[timezone_id] => America/Eirunepe ) [2] => Array ( [dst] => 1 [offset]
=> -14400 [timezone_id] => America/Rio_Branco ) [3] => Array ( [dst]
=> 1 [offset] => -14400 [timezone_id] => Brazil/Acre ) )
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: PHP Displaying the date and time in your timezone Tutorial
Post your Comment