converting a time to a different timezone with php

前端 未结 6 2013
鱼传尺愫
鱼传尺愫 2020-12-11 17:38

$timeposted = \"7:10pm\";

This value is currently Canada time (quebec). I\'m trying to find a way to convert it to France\'s time. How can i do that ?

6条回答
  •  青春惊慌失措
    2020-12-11 17:59

    This is my function that take time from a mysql db (which I've stored entirely in UTC) and converts to a new timezone and formats it simply.

    function changetimefromUTC($time, $timezone) {
        $changetime = new DateTime($time, new DateTimeZone('UTC'));
        $changetime->setTimezone(new DateTimeZone($timezone));
        return $changetime->format('m/d/y h:i a');
    }
    

    This is a list of supported timezones http://us1.php.net/manual/en/timezones.php

提交回复
热议问题