UTC Date/Time String to Timezone

前端 未结 6 640
萌比男神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:31

    function _settimezone($time,$defaultzone,$newzone)
    {
    $date = new DateTime($time, new DateTimeZone($defaultzone));
    $date->setTimezone(new DateTimeZone($newzone));
    $result=$date->format('Y-m-d H:i:s');
    return $result;
    }
    
    $defaultzone="UTC";
    $newzone="America/New_York";
    $time="2011-01-01 15:00:00";
    $newtime=_settimezone($time,$defaultzone,$newzone);
    

提交回复
热议问题