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!
it is currently 12:19 EST and the date this displays is 11:19 so it doesn't compensate for the recent time change with daylight savings time. Any way to adjust the code to reflect this change?
I'm wondering why the date is wrong in the first place? Is the server in a different timezone than you are? date('I') (capital i) will tell you if you're in DST or not.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Well, you can shift it on the server side, but that'd just be a fix for people in your timezone. If you want to give the proper time on the page for everyone, you're going to need to do some client-side coding.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Well, you'd still have the problem of users at 11:30 PM seeing it as tomorrow (or vice versa)
Okay. Basically, the user gets to define an offset, like +3:00, or -6:00. You simply add that many seconds (hours * 60 * 60) to the time, output using gmdate() and you're set.
This doesn't take into effect DST: the user will have to manually change it every time that happens. Theoretically, you can have the user define the region they live in, and then use server-side records to determine the offset (which will take DST and other stuff into effect). I'm not exactly sure how you would go about doing that though...
it suprised me to think that there is no way to get the users GMT offset from a PHP function, I started thinking that with a proper IP tracking API you could get their location, then based on that calculate their GMT offset, I started looking around, and someone has beat me to the punch... Its not exactly a tutorial and the guy even states that its not a working script, its a proof on concept, but I think if someone was to take the time and has the knowledge (cough cough feyd ) they could put something like this together... could be a handy script for the entire PHP community
Considering when I was living in California, my IP was in Chicago, I can tell you it's not reliable. Even now, my IP shows up as being in Virginia. Notice my location to the left..
It's better to just ask the user what their time offset is (and possibly allow them to choose to observe daylight savings) .. I always store time using gmmktime() then on demand offset that number to reflect the time relative to the observer.
If the choose automatic time synching, I use a Javascript toy or their option of selection if Javascript is disabled to pull and pass their computer's current time offset when they log in. The automatic adjustment doesn't affect their personal preference, but does allow the time to reflect what is set on the computer they are using. Otherwise, it will use their personal preference or the "server" local time if none is given.
I was thinking of the javascript comparision of their time settings as another method, but I hate relying on javascript... I guess what it really boils down to is how important is this feature.... are you just displaying the time up top to make it look flashy or is the time stamp of importance to the entire application... if your answer to that is the latter of the two, I would suggest the user offset selection, otherwise... the choice is yours