Forum Moderators: coopster

Message Too Old, No Replies

Displaying time for specific city

         

neophyte

1:21 am on Feb 11, 2005 (gmt 0)

10+ Year Member



I have a client who owns a resort in the Philippines. This client wants to show the current time at the resort on his home page.

How would this be done with PHP? Is it some calculation based upon GMT? I think (I'll have to check) that the Philippines is +8 GMT...so is that what you'd have to do: create a snippet that grabs the current GMT and add "8" to it?

Zipper

6:35 am on Feb 11, 2005 (gmt 0)

10+ Year Member



well, you could easily use client side scripting like javascript to do it.. but if you need to use php do something like,

<?
$offset = 8; // difference to GMT in hours
$phil_time = date("h:i:s A", time() - date("Z") + ($offset * 3600));
echo $phil_time;
?>

you could also use mktime() but I personally try to avoid it as it has its own little discrepancies.

dcrombie

10:24 am on Feb 11, 2005 (gmt 0)



Even easier, use PHP to set the timezone:

# set timezone for dates to New York time 
putenv("TZ=America/New_York");

;)

neophyte

1:17 am on Feb 12, 2005 (gmt 0)

10+ Year Member



Thanks both to Zipper and dCrombe.

dCrombe's example intrigues me, but how do you show the result?

After you set the time zone (putenv("TZ=America/New_York");) do you use a date function to output the current time in the time zone set?

Also, will the time display update, or do you have to run some sort of loop to get an updated time display?

Last question: I've done some searches on "TZ" on php.net and can't find a listing of timezones to use. Since I want to use a time zone from the Philippines, I'm assuming it would be something like "TZ=Asia/Philippines" but haven't find any documentation to support that assumption.

dcrombie

11:13 am on Feb 12, 2005 (gmt 0)



<?PHP 
putenv("TZ=America/New_York");
echo "<P>server timezone set to: ",getenv("TZ"),"<br>\n";
echo date("r"),"</P>\n\n"
?>

<?PHP 
putenv("TZ=Asia/Manila");
echo "<P>server timezone set to: ",getenv("TZ"),"<br>\n";
echo date("r"),"</P>\n";
?>

And no, it won't update after the page has loaded because that requires something that executes in the browser, such as JavaScript, and not PHP which runs on the server.

;)

neophyte

2:08 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



decrombe -

Thanks so much!

Neophyte

coopster

5:20 pm on Feb 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




Last question: I've done some searches on "TZ" on php.net and can't find a listing of timezones to use. Since I want to use a time zone from the Philippines, I'm assuming it would be something like "TZ=Asia/Philippines" but haven't find any documentation to support that assumption.

Search your system for "zoneinfo". You'll probably find it in /usr/share. A search on the net for "TZ environment variable" or "zoneinfo" will turn up plenty 'o reading ;)