change timezones in php

Reply

Join Date: Jun 2009
Posts: 6
Reputation: gilbertsavier is an unknown quantity at this point 
Solved Threads: 0
gilbertsavier gilbertsavier is offline Offline
Newbie Poster

change timezones in php

 
0
  #1
Aug 14th, 2009
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 .

  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.
Thanks & regards
Lokananth
[url "http://www.mioot.com"]Live Chat Software[/url] By miOOt
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: danishbacker is an unknown quantity at this point 
Solved Threads: 5
danishbacker's Avatar
danishbacker danishbacker is offline Offline
Junior Poster in Training

Re: change timezones in php

 
0
  #2
Aug 14th, 2009
sorry i am not sure about the code (pear package for date)
but i used to change the timezone as following
  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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC