Results 1 to 7 of 7

Thread: trouble with gmdate(), offset doesnt work

  1. #1
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default trouble with gmdate(), offset doesnt work

    using the code

    PHP Code:
    <?php
    echo gmdate("l, F jS, Y \- h:i:s A"mktime(-12));    echo " - (GMT - 12:00 hours) Enitwetok, Kwajalien";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-11));    echo " - (GMT - 11:00 hours) Midway Island, Samoa";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-10));    echo " - (GMT - 10:00 hours) Hawaii";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-9));    echo " - (GMT - 9:00 hours) Alaska";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-8));    echo " - (GMT - 8:00 hours) Pacific Time (US &amp; Canada)";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-7));    echo " - (GMT - 7:00 hours) Mountain Time (US &amp; Canada)";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-6));    echo " - (GMT - 6:00 hours) Central Time (US &amp; Canada), Mexico City";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-5));    echo " - (GMT - 5:00 hours) Eastern Time (US &amp; Canada), Bogota, Lima, Quito";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-4));    echo " - (GMT - 4:00 hours) Atlantic Time (Canada), Caracas, La Paz";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-3));    echo " - (GMT - 3:00 hours) Brazil, Buenos Aires, Georgetown, Falkland Is.";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-2));    echo " - (GMT - 2:00 hours) Mid-Atlantic, Ascention Is., St Helena";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(-1));    echo " - (GMT - 1:00 hours) Azores, Cape Verde Islands";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(0));    echo " - (GMT) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(1));    echo " - (GMT + 1:00 hours) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(2));    echo " - (GMT + 2:00 hours) Kaliningrad, South Africa, Warsaw";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(3));    echo " - (GMT + 3:00 hours) Baghdad, Riyadh, Moscow, Nairobi";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(4));    echo " - (GMT + 4:00 hours) Abu Dhabi, Baku, Muscat, Tbilisi";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(5));    echo " - (GMT + 5:00 hours) Ekaterinburg, Islamabad, Karachi, Tashkent";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(6));    echo " - (GMT + 6:00 hours) Almaty, Colomba, Dhakra";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(7));    echo " - (GMT + 7:00 hours) Bangkok, Hanoi, Jakarta";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(8));    echo " - (GMT + 8:00 hours) Beijing, Hong Kong, Perth, Singapore, Taipei";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(9));    echo " - (GMT + 9:00 hours) Osaka, Sapporo, Seoul, Tokyo, Yakutsk";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(10));    echo " - (GMT + 10:00 hours) Melbourne, Papua New Guinea, Sydney, Vladivostok";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(11));    echo " - (GMT + 11:00 hours) Magadan, New Caledonia, Solomon Islands";    echo "<BR>";
    echo 
    gmdate("l, F jS, Y \- h:i:s A"mktime(12));    echo " - (GMT + 12:00 hours) Auckland, Wellington, Fiji, Marshall Island";    echo "<BR>";
    ?>
    it appears as
    Thursday, December 7th, 2006 - 05:11:12 PM - (GMT - 12:00 hours) Enitwetok, Kwajalien
    Thursday, December 7th, 2006 - 06:11:12 PM - (GMT - 11:00 hours) Midway Island, Samoa
    Thursday, December 7th, 2006 - 07:11:12 PM - (GMT - 10:00 hours) Hawaii
    Thursday, December 7th, 2006 - 08:11:12 PM - (GMT - 9:00 hours) Alaska
    Thursday, December 7th, 2006 - 09:11:12 PM - (GMT - 8:00 hours) Pacific Time (US & Canada)
    Thursday, December 7th, 2006 - 10:11:12 PM - (GMT - 7:00 hours) Mountain Time (US & Canada)
    Thursday, December 7th, 2006 - 11:11:12 PM - (GMT - 6:00 hours) Central Time (US & Canada), Mexico City
    Friday, December 8th, 2006 - 12:11:12 AM - (GMT - 5:00 hours) Eastern Time (US & Canada), Bogota, Lima, Quito
    Friday, December 8th, 2006 - 01:11:12 AM - (GMT - 4:00 hours) Atlantic Time (Canada), Caracas, La Paz
    Friday, December 8th, 2006 - 02:11:12 AM - (GMT - 3:00 hours) Brazil, Buenos Aires, Georgetown, Falkland Is.
    Friday, December 8th, 2006 - 03:11:12 AM - (GMT - 2:00 hours) Mid-Atlantic, Ascention Is., St Helena
    Friday, December 8th, 2006 - 04:11:12 AM - (GMT - 1:00 hours) Azores, Cape Verde Islands
    Friday, December 8th, 2006 - 05:11:12 AM - (GMT) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia
    Friday, December 8th, 2006 - 06:11:12 AM - (GMT + 1:00 hours) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome
    Friday, December 8th, 2006 - 07:11:12 AM - (GMT + 2:00 hours) Kaliningrad, South Africa, Warsaw
    Friday, December 8th, 2006 - 08:11:12 AM - (GMT + 3:00 hours) Baghdad, Riyadh, Moscow, Nairobi
    Friday, December 8th, 2006 - 09:11:12 AM - (GMT + 4:00 hours) Abu Dhabi, Baku, Muscat, Tbilisi
    Friday, December 8th, 2006 - 10:11:12 AM - (GMT + 5:00 hours) Ekaterinburg, Islamabad, Karachi, Tashkent
    Friday, December 8th, 2006 - 11:11:12 AM - (GMT + 6:00 hours) Almaty, Colomba, Dhakra
    Friday, December 8th, 2006 - 12:11:12 PM - (GMT + 7:00 hours) Bangkok, Hanoi, Jakarta
    Friday, December 8th, 2006 - 01:11:12 PM - (GMT + 8:00 hours) Beijing, Hong Kong, Perth, Singapore, Taipei
    Friday, December 8th, 2006 - 02:11:12 PM - (GMT + 9:00 hours) Osaka, Sapporo, Seoul, Tokyo, Yakutsk
    Friday, December 8th, 2006 - 03:11:12 PM - (GMT + 10:00 hours) Melbourne, Papua New Guinea, Sydney, Vladivostok
    Friday, December 8th, 2006 - 04:11:12 PM - (GMT + 11:00 hours) Magadan, New Caledonia, Solomon Islands
    Friday, December 8th, 2006 - 05:11:12 PM - (GMT + 12:00 hours) Auckland, Wellington, Fiji, Marshall Island
    i think it auto conforms to your timezone on your pc when using gmdate but im not sure, I want a user to be able to select the choice but I gotta get it working first... can someone tell me by going to http://michael.hungerford.us/gmttimes.php and telling me what the time for (gmt) area is for you so i can check if it auto detects from your pc location?

    on my pc my current time is (GMT + 01:00) so its just being wierd, im not sure why

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    what any of the date/time functions in php do is use the server time that the webpage is on. IE, if your server is your home computer, and the current time is 5:30pm on 12/8/06, then that will be the date PHP uses. There are a way around this, but you will need to have safe mode off to do it. I cannot remember exactly what it is but you could probably find it in the comments on the PHP.net website.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    my error seems to be in the mktime, i erased it so it is

    PHP Code:
    echo gmdate("l, F jS, Y \- h:i:s A");    echo " - (GMT) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia";    echo "<BR>"
    and it appears ot display the correct time now...

  4. #4
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    gmdate shouldnt use server though since it uses gmt time conversion

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Yea, you're right, it uses the gmt conversion from the server time. I misunderstood the original post, and simply glanced over the posted code. Sorry for the mishap.
    Last edited by thetestingsite; 12-09-2006 at 05:42 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Uh... what's wrong with that? It looks perfectly correct to me.

    The other posters here are right: PHP is run on the server, not the client, so it uses the server's time.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    gmdate should set it equivalent to gmt time though... I will use separate date and do like

    Code:
    $time = gmdate("h") + (value of something else...)
    echo gmdate("l, F jS, Y \- "
    echo $time;
    echo ":i:s A";

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •