Grow your CSS skills. Land your dream job.

Detect timezone?

  • # February 21, 2012 at 4:54 pm

    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?

    # February 21, 2012 at 4:55 pm

    GMT+0 that is

    # February 21, 2012 at 6:57 pm

    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

    # February 22, 2012 at 4:05 am

    That is true :) Thank you :)

    # February 22, 2012 at 5:44 am

    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;
    }
    date_default_timezone_set($thetimezone);

    And on the wall, it’s simply a $timestamp variable pulling out the timestamp for that post?

    # February 23, 2012 at 6:48 am

    @bungle – Any ideas?

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".