Home Php PHP Displaying the date and time in your timezone Tutorial

 
 

Share on Google+Share on Google+

PHP Displaying the date and time in your timezone Tutorial

Advertisement
Display the time and date on your website, accurate to your timezone offset.

PHP Date Time Zone

     

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 ) )

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 12, 2009

Related Tutorials

Discuss: PHP Displaying the date and time in your timezone Tutorial  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com