Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP Timezones

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #25283

    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

    #59806
    ikthius
    Member

    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

    #59820

    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

    #59810
    ikthius
    Member
    "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?

    #59844

    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?

    #60443
    digitalpbk
    Member

    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

    #62453
    edot3
    Member

    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)
  • The forum ‘Back End’ is closed to new topics and replies.