Converting Between Timezones With PHP

by pradeep on October 3, 2008

in PHP

PHP comes with an in-built function to display time in your required format, but what if you want to display date and time according to user's timezone, that's where PEAR package Date comes in. Let's see how we can convert a date in GMT to IST.

<?php
// include class
include ("Date.php");
 
// initialize object
$d = new Date("2008-10-03 16:23:48");
 
// set server time zone
$d->setTZByID("GMT");
 
// print server time
echo "Local time is " . $d->format("%A, %d %B %Y %T") . "\n";
 
// convert to IST
$d->convertTZByID("PST");
 
// output converted date/time
echo "Destination time is " . $d->format("%A, %d %B %Y %T");
?>

Share:
  • Digg
  • Facebook
  • StumbleUpon
  • Technorati
  • Twitter
Other Related Posts:
  1. Get Visitor IP Address
  2. How to Write Good Press Releases

Want More Tips on How to Make Money Online?
Enter your Name and Email below to subscribe and start 1 month free course now.

Name:
Email:
You would require to confirm your email address before we send you any updates. We respect your privacy as much as you do.
Powered by Aweber
blog comments powered by Disqus

Previous post:

Next post: