Get current date, given a timezone in PHP?

前端 未结 5 1505
灰色年华
灰色年华 2020-12-04 13:32

I want to get todays date given a time zone in Paul Eggert format(America/New_York) in PHP?

5条回答
  •  再見小時候
    2020-12-04 13:50

    I have created some simple function you can use to convert time to any timezone :

    function convertTimeToLocal($datetime,$timezone='Europe/Dublin') {
            $given = new DateTime($datetime, new DateTimeZone("UTC"));
            $given->setTimezone(new DateTimeZone($timezone));
            $output = $given->format("Y-m-d"); //can change as per your requirement
            return $output;
    }
    

提交回复
热议问题