determine timezone (with daylight savings)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

determine timezone (with daylight savings)

Post by Burrito »

I am setting up an event scheduler and when my users create an account, they select their timezone, I want to be able to send reminder emails about upcoming events with the time they need to log in to the event (their correct time (given their zone)). My problem is, I'm in AZ and we don't do daylight savings here so I can't just do +1, +2, +3, -1 for the hours for the timezone they've selected as it will be different depending on whether or not you all are on ST or DT. Is there some way I could determine whether it's daylight or standard time dynamically? Is there a calendar function built in that has these dates for say...15 years into the future? Has someone built one they'd be willing to share? Is there another way to make this determination?

please advise,
thx,
Burriskimo
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

generate a GMT timestamp (safest) .. I believe the locale settings will adjust accordingly, or if you look down the page a bit... there was a reference to worldtimeserver.com I believe..
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ok so if I generate a timestamp, won't that be for MY server (since I'm doing this all server side)? How could I then adjust the time according to the setting they've chosen when they registered?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you make a GMT timestamp, it'll be adjusted from your server's locale settings to GMT. From there, you can conver to someone else's timezone relatively easy.

In the past, I've done a little Javascript (with graceful fallback) that determined the timezone of the machine viewing the server, which is sent to the server through an image query, or some other form you can decide. A checkbox is placed in the user settings if Javascript is enabled in their browser. Otherwise, they are considered to not observe daylight savings..
Post Reply