UTC Date/Time String to Timezone

前端 未结 6 629
萌比男神i
萌比男神i 2020-12-02 10:03

How do I convert a date/time string (e.g. 2011-01-01 15:00:00) that is UTC to any given timezone php supports, such as America/New_York, or Europe/San_Marino.

6条回答
  •  死守一世寂寞
    2020-12-02 10:24

    PHP's DateTime object is pretty flexible.

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

提交回复
热议问题