Grow your CSS skills. Land your dream job.

PHP Timezones

  • # June 27, 2009 at 4:24 am

    Hi guys, I am building an application in PHP and I have got to the stage at which I need to know how to find out the user’s timezone. I’d like to know if there is a way of using the date() function to retrieve it. If there isn’t a way of doing it then I will just ask the user to input their timezone.

    By the way I know this can be done with JavaScript, but I just wanted to know if it is possible with PHP.

    Thanks in advance.

    -Tom

    # June 27, 2009 at 7:14 am

    test this:
    http://us3.php.net/manual/en/function.d … ne-get.php

    also you can show the abbreviated version with echo date(T);
    this gives me BST

    as far as i know this is server time, not client time

    # June 27, 2009 at 12:18 pm

    Thanks for the reply, I just ended up doing this:

    Code:
    $gmt = date(H) + 7;
    $hoursNow = $gmt + $timeZone;

    The timezone on my server is -7 and the $timeZone variable is a number given to the PHP by the users input. Thanks anyway!

    the finished results of what I was doing can be found here: http://tomsbigbox.com/alive

    -Tom

    # June 28, 2009 at 5:21 am
    "tomwalters5678" wrote:
    Thanks for the reply, I just ended up doing this:

    Code:
    $gmt = date(H) + 7;
    $hoursNow = $gmt + $timeZone;

    The timezone on my server is -7 and the $timeZone variable is a number given to the PHP by the users input. Thanks anyway!

    the finished results of what I was doing can be found here: http://tomsbigbox.com/alive

    -Tom

    so really the drop down menu means you don’t need to know what the users timezone is, as they can use what they like?

    # June 28, 2009 at 11:12 am

    Yeah, my idea was to make it more automated than it is, but in the end I suppose a little more user input can’t hurt – by the way, do you think the extended user input works?

    # July 9, 2009 at 11:44 pm

    There is a way to find the users timezone but that would require you to have an IP to location table. Map the IP address which is obtained from the

    Code:
    $_SERVER["REMOTE_ADDR"]

    variable to a location and then to a timezone. This method cannot be accurate but atleast can help users in selecting their timezones. The better method is to do using js and calculate the client offset and return it to our server.

    http://digitalpbk.blogspot.com/2009/05/crontab-server-timezone-php-date.html

    # August 20, 2009 at 9:23 am

    I get stuck with this every time I do something with PHP and a timezone since I am an English developer and my server is in the US.

    You can use the putenv function in php to put an environmental variable;

    putenv (‘TZ=Europe/London’);

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

You must be logged in to reply to this topic.

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