2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > php 不同时区时间转换 在PHP中将DateTime字符串转换为不同的时区

php 不同时区时间转换 在PHP中将DateTime字符串转换为不同的时区

时间:2021-05-08 00:08:10

相关推荐

php 不同时区时间转换 在PHP中将DateTime字符串转换为不同的时区

好吧,我有以下代码

$from = "Asia/Manila";

$to = "UTC";

$org_time = new DateTime("-05-15 10:50:00");

$org_time = $org_time->format("Y-m-d H:i:s");

$conv_time = NULL;

$userTimezone = new DateTimeZone($from);

$gmtTimezone = new DateTimeZone($to);

$myDateTime = new DateTime($org_time, $gmtTimezone);

$offset = $userTimezone->getOffset($myDateTime);

$conv_time = date('Y-m-d H:i:s', $myDateTime->format('U') + $offset);

echo $conv_time;

使用此代码我想将-05-15 10:50:00转换为UTC和-8时区(我使用美国/温哥华)但它给了我一个奇怪的结果

06001

而对于美国/温哥华

Asia/Manila > America/Vancouver

-05-16 02:50:00 = the correct is -05-14 19:50

哪里出错了?

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。