SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Guru okrogius's Avatar
    Join Date
    Mar 2002
    0 Post(s)
    0 Thread(s)

    detecting gmt timezone offset

    I'm trying to detec the user's timezone from javascript. (this is non essential, just that I can get it via javascript I would alltogether hide the form element for it and fill it in automatically)

    I've tried date.getTimezoneOffset()/60 (where date is a a Date() object), and it works nicely, except for one small issue - it alwasy returns a positive offset, no matter if the user is in -5 or +5 GMT for instance.

    Next thing I tried is converting a date object to a string. It ended up having "... -5000 (Eastern Standard...". Good I think, as I can parse it. But then this went downhill as IE doesn't send that -5000 and just sends an "...EST..." Needless to say, not my idea of fun parsing when each browser has it's own version.

    Is there something else I'm missing with which I can get the offset?

    EDIT: found myself a solution using both server side scripting, and java_script_:
    PHP Code:
      Math.round((d.getHours()*3600+d.getMinutes()*60+d.getSeconds())/3600)-<?php echo gmdate('H',time()); ?>
    But would be nice if I can do it all with javascript.
    Last edited by Codename49; Mar 21, 2004 at 12:13.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts