PHP若何转换时区?
起首实例化“DateTimeZone”类,实例化参数为转化的时区;而后实例化“DateTime”类,其参数1为要转换的工夫,参数2为“DateTimeZone”工具;最初挪用“DateTime”工具的format便可。
代码示例
<?php function changeTimeZone($date_time, $format = 'Y-m-d H:i:s', $to = 'Europe/Rome', $from = 'Asia/Shanghai') { $datetime = new DateTime($date_time, new DateTimeZone($from)); $datetime->setTimezone(new DateTimeZone($to)); return $datetime->format($format); } $time = changeTimeZone('2018-12-19 00:00:00'); $t = changeTimeZone('2018-12-19 00:00:00', 'Y-m-d'); echo $time; echo $t;
保举教程:《PHP》
以上就是PHP若何转换时区?的具体内容,更多请存眷资源魔其它相干文章!
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!