Forums Get help. Give help.

Detect timezone?
  • schartschart February 21
    So I'm using a timestamp in my database to save the time when the user posts a update. Now I've done some tweaks and now it returns "x hours ago" and stuff like that. My problem is that it is set to be GMT even if the user browsing is in America or Australia, it might say 5 hours ago when the user posts. Now how do I change my timezone to the one of the user browsing?
  • schartschart February 21
    GMT+0 that is
  • bunglebungle February 21
    If you have registered users than you can have them set their timezone in prefs which you can then store as an offset

    If they are anonymous posting you can use javascript to grab the timezone


    var timeZone = (new Date().gettimezoneOffset()/60)*(-1);


    and then fill a hidden field with it to grab and store with the message, you can then use that offset to adjust the message times
  • schartschart February 22
    That is true :) Thank you :)
  • schartschart February 22
    OK, I've got timezone set up in the database and register form, the values are like "America/Los_Angeles" and stuff.

    Now, how do I plus/minus from the $timestamp (0000-00-00 00:00:00) to be the same as in their timezone?



    //some mysql stuff here to pull out information for user browsing
    $thetimezone = $row['timezone'];
    }
    date_default_timezone_set($thetimezone);


    And on the wall, it's simply a $timestamp variable pulling out the timestamp for that post?
  • schartschart February 23
    @bungle - Any ideas?



Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

Tips

Just some helpful hints to get the most out of the forums.