sorry guys.. i may sound stoopeed here but i am kinda slow with time stuffs.. gmt/utc, etc etc.. cant quite grasp it ye

anyway as of now i need quickly to be able to call time() or date() but for a specific country..

i tried playing around with gmdate gmmktime and other things.. i just cant quite get it..

say for example, if i run a script that tells the time, i want it to be able to tell the date and time of LONDON no matter what the timezone of the server the script is on

can you help pls? thank you

RTFM <<-- i have and tried things.. im just not getting it.. 🙁

    <?php
    // Define the timezones and their offsets
    // 'Zone Label' => Offset
    $timezones = Array('GMT' => 0, 'US EST' => -5, 'US PST' => -8);
    
    // Set up a form to change the timezone
    // Automatically update the page on a timezone change
    echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
        <select name="tz" onChange="this.form.submit();">';
    
    // Create a drop-down list of timezones
    foreach($timezones as $zone => $offset)
    {
        echo '<option value="'.$offset.'_'.$zone.'"';
        if($offset.'_'.$zone == $_POST['tz']){ echo ' selected'; }
        echo '>'.$zone.'</option>';
    }
    echo '</select>
    </form>';
    
    // Give a default zone of there is no zone given
    if(!isset($_POST['tz']))
    {
        $_POST['tz'] == '-5_US EST';
    }
    
    // Get the offset and timezone from the POST array
    list($offset, $zone) = explode('_', $_POST['tz']);
    
    // Display the current zone and its offset
    echo 'The timezone is: '.$zone.' ( '.$offset.' )<br>';
    
    // Display the current time
    echo 'The current time is: '.gmdate('m/d/Y h:i a', time()+3600*($offset+date("I")));
    ?>

    That will output:

    The timezone is: US EST ( -5 )
    The current time is: 10/13/2005 01:18 am

    [man]gmdate/man <-- Read the user notes
    Basically, what the last line does is create a date (just like date('m/d/Y') would) based upon a specific time. The time is defined as:
    now + ( (60 seconds 60 minutes) (timezone_offset + DST) )

    So you take the timezone hour offset, add the DST offset (1 if it's the winter, 0 if it's the summer), and mulitply that by the amount of seconds in one hour (3600) and then add that to the "now" timestamp. Then the gmdate() function displays the result.

    Just add the time-zones to the array, and voila!!

    ~Brett

      wow.. i didnt know it was that complicated..well not really THAT complicated but i didnt know it invloved so much more than just adding a parameter into a function like gmdate()

      right now in my code im manually adding the GMT offset, well similar to what you're suggesting.... just thought there's a quicker way.. like function made just for that. no more adding etc.. just a GMT parameter like "-8" or "+8".. guess not...

      sooo......

      clarification....

      gmdate("Y m d H:i", time()) returns the date and GMT 0 right? and that is GMT of UK right?

      so is the following statement true:

      to calculate my country's current HOUR (Philippines)

      echo gmdate("h",time()) + 8; //current hour in GMT plus 8 (Hongkong/Philippines)

      yah?

      thanks!

        No, if you use gmdate("h", time()+8) you will get the current time plus 8 seconds. You need to use the math to add the proper amount of seconds to add 8 hours to the GMT time.

        time() + ( (60 seconds 60 minutes) (timezone_offset + DaylightSavingsTime) )

        Without that, your conversion from GMT to Phillippines won't work. What you could do is take the line above, and just replace timezone_offset with "8" and use that (if you only want the Phillippines. Otherwise, you can use my little form.

        But the line I gave you is guaranteed to work on any server and give you the proper time, which is what you asked for.

        ~Brett

          Instead of using colloquial names for timezones as bpat1434 does, you could use a more systematic system. The military scheme uses "Z" for UTC; "a" is UTC-1, "b" is UTC-2, and so on around to "m" which is UTC-12 (skipping "j"). Then "n" is UTC+12, "o" is UTC+11, and so on to "y" which is UTC+12. If you use strtotime() you can use these to specify timezones (e.g., strtotime("now u")). Of course, that doesn't accout for Daylight Saving.

          Unfortunately, neither does bpat1434's code; date('I') would use whatever Daylight Saving rule is in effect for the server's location, which presumably isn't the one that applies to the territory you're interested in (otherwise you wouldn't be having to do this).

          Current timezone and daylight saving rules are maintained here.

            thank you both..

            perhaps this should be in the PHP wish list then.. a native php function that gets the exact time and date of a certain location, on any server it is executed on.. and only need the parameters of date format and timezone setting....

            like real_gmdate(dateformat,timestamp, timezone setting)

            oh well

              Write a Reply...