Search code examples
phptimegmt

Php Convert time in gmt format


I have this string 2012-06-27 16:17:06 and I want to convert it to GMT format.
How can I do that?

Thanks a lot.


Solution

  • PHP's DateTime Object is a good choice:

    $GMT = new DateTimeZone("GMT");
    $date = new DateTime( "2011-01-01 15:00:00", $GMT );
    $date->setTimezone( $newTZ );
    echo $date->format('Y-m-d H:i:s');