Converting Dates to GMT

Discussion in 'PHP' started by Weirfire, May 1, 2007.

  1. #1
    <?php
    
    $date1 = 'Tue, 01 May 2007 09:31:55 EDT';
    $date2 = 'Thu, 26 Apr 2007 06:44:00 PDT';
    $date3 = 'Tue, 01 May 2007 14:07:26 GMT';
    
    ?>
    PHP:
    Is there an easy way to convert all these dates to GMT values even if I don't know what the timezone will be every time?
     
    Weirfire, May 1, 2007 IP
  2. crazeinc

    crazeinc Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can get the gmt offset via javascript with getTimezoneOffset(), but if you have the dates stored in php, that complicates things a bit.
     
    crazeinc, May 1, 2007 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    you have the gmdate() functions which outputs a GMT date. I think something like this should work.

    
    
    $date = 'Tue, 01 May 2007 09:31:55 EDT';
    
    $dateGMT = gmdate('D, d M Y H:i:s',strtotime(substr($date,-3,3),substr($date,0,-4)));
    
    
    PHP:
     
    jestep, May 1, 2007 IP