NYCPHP Meetup

NYPHP.org

[nycphp-talk] Getting GMT bias from browser

David Krings ramons at gmx.net
Mon Oct 9 21:29:21 EDT 2006


At 11:50 AM 10/9/2006, you wrote:
>Yeah, there's no good way to do this other than to have the user's
>browser tell you what it thinks the date/time is.  The Javascript Date
>() object will, by default, return a date string that has the GMT
>offset in it.
>
>Mon Oct 09 2006 10:32:00 GMT-0500 (CDT)
>
>It also has a method called getTimezoneOffset(), which tells you the
>(+/-) minutes away from GMT the browser is.  You could just test the
>value of $_COOKIE in php, redirect to a page that sets a cookie, and
>then go back to the main page.  It sucks, but it works.


Thank you very much for the script code. I did try it out and it indeed 
sets the GMT_Bias in $_COOKIE. So far so good. Being in CT I expected the 
bias to be 300, but it is 240. I also placed myself in different timezones 
and not surprisingly, it comes up with the same result. So, how about 
putting my server back on the East Coast and make my  client now on a 
different PC to be in Germany. As bias I get this time -120 although I 
expected it to be -60. That together makes 360 minutes and that results to 
6 hours difference, which indeed is the correct difference between here and 
Germany.
So I guess what I need to do know is add some protection in case the 
browser does not accept cookies and figure out what my server GMT bias is 
and arrange that with the browser GMT bias to calculate the browser time 
based on the server time and the GMT difference. I probably can do that in 
one go by mashing the biases together and add the positive or negative 
bias. A quick look on the GMT website shows that the 240 and -120 are 
indeed correct due to DST. So I should do some more testing by placing both 
client and server in that week where the US is off in its DST setting 
compared to the rest of the world, which by the way really sucks big time 
when dealing with folks in Germany and the difference is out of a sudden 7 
hours. How was that? By next year it gets even worse as DST in the US lasts 
one month longer than everywhere else. Ah well, now I have a nice script 
that will help me figure this all out. If I just wouldn't have a pesky job 
that takes the best 8 hours of my day......

Thank you very much, that was really nice of you !


         David K. 




More information about the talk mailing list