943,635 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 994
  • PHP RSS
Aug 14th, 2009
0

change timezones in php

Expand Post »
Hi,
PHP scripting language have an built in function to change between the timezones , you will need the PEAR package . In the following example show you how to convert from GMT system format to IST Format .

php Syntax (Toggle Plain Text)
  1. <?php
  2. // include class
  3. include ("Date.php");
  4.  
  5. // initialize object
  6. $d = new Date("2008-10-03 16:23:48");
  7.  
  8. // set server time zone
  9. $d->setTZByID("GMT");
  10.  
  11. // print server time
  12. echo "Local time is " . $d->format("%A, %d %B %Y %T") . "\n";
  13.  
  14. // convert to IST
  15. $d->convertTZByID("PST");
  16.  
  17. // output converted date/time
  18. echo "Destination time is " . $d->format("%A, %d %B %Y %T");
  19.  
  20. ?>
Last edited by peter_budo; Aug 14th, 2009 at 1:08 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gilbertsavier is offline Offline
6 posts
since Jun 2009
Aug 14th, 2009
0

Re: change timezones in php

sorry i am not sure about the code (pear package for date)
but i used to change the timezone as following
php Syntax (Toggle Plain Text)
  1. <?Php
  2. if(function_exists('date_default_timezone_set')){
  3. date_default_timezone_set("Asia/Calcutta");
  4. }
  5. else{
  6. putenv("TZ=Asia/Calcutta");
  7. }
  8. $date = date('l jS \of F Y h:i:s:c A');
  9. ?>

Just give it a try
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
danishbacker is offline Offline
97 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP loop through database and limit number of entries
Next Thread in PHP Forum Timeline: Links Partner Finder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC