Forum Moderators: coopster

Message Too Old, No Replies

Time and Date Conversion - US to Philippines

Not sure how to do it

         

neophyte

11:16 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



Hello All -

I've got a project that requires the local time (Philippine time) to show up on a clients site...as well as within a database. Right now when I reflect the "current date and time" on the clients site, it is relfected as US Mountian time which is accurate because the client's server space is in Utah.

How do I do this. It would be something like:

1. get GMT
2. get the gmt offset from Utah to the Philippines
3. convert GMT into current local date and time.

... is this correct?

So, if the GMT offset from Utah to the PI's is +16 (or whatever it is) how do I convert that result back into a "real date and time" format?

All help greatly appreciated.

Neophyte

barns101

12:19 pm on Sep 16, 2006 (gmt 0)

10+ Year Member



Utah is 14 hours behind the Philippines. So you could get the current server time with mktime() [php.net] and then add 14 hours, which is 50400 seconds, and that will give you the current time in the Philippines (all based on Unix timestamps). Then you can format the time and date however you like with date() [php.net].

neophyte

11:55 pm on Sep 16, 2006 (gmt 0)

10+ Year Member



barns101 -

That worked very nicely. Thanks very much for the tip!

Neophyte

barns101

9:14 am on Sep 17, 2006 (gmt 0)

10+ Year Member



Glad it works for you. Remember to beware of time changes (like if one timezone adds an hour in the summer like we do in the UK).

neophyte

2:33 pm on Sep 17, 2006 (gmt 0)

10+ Year Member



barns101 -

Indeed you're right - I've considered agonizing over that very issue (daylight savings time vs. "standard time" in the states). The essence of this post concerned a customers server space which - as previously mentioned - is in Utah which is on Mountian time. I don't know if DST is in effect in this region of the US but I'll check tomorrow.

If it is - or atleast for the sake of making my function more flexible for additional projects - how DOES one go about allocating for the addition or subtraction of an hour?

I suppose the "chop-wood, carry-water" way would be to determine time zones of target areas where the time/date would be displayed, get the date, check it against a look-up list, and then adjust the offset (in seconds) to accommodate accordingly. Yuck.

Is there an easier way?

Neophyte

barns101

10:06 am on Sep 18, 2006 (gmt 0)

10+ Year Member



The date() [php.net] function can tell you whether DST is in effect in your server's timezone. Based on that you could decide whether or not to add an hour (3600 seconds) to your timestamp before outputting the date/time.

neophyte

12:04 am on Sep 19, 2006 (gmt 0)

10+ Year Member



barns101 -

Cool my friend. Thanks again; you've been a big help to me with this stuff.

Best regards!