我需要知道两个城市之间的时差。我也有两个城市及其时区的当前时间。我尝试使用 getOffset 获取差异,但它显示的是 GMT(UTC) 与相应地点之间的时差。
下面是我在 php 中用来找出区别的代码:
$dateTimeZone1 = new DateTimeZone("Asia/Calcutta");
$dateTimeZone2 = new DateTimeZone("America/New_York");
$dateTime1 = new DateTime("now", $dateTimeZone1);
$dateTime2 = new DateTime("now", $dateTimeZone2);
$timeOffset = $dateTimeZone1->getOffset($dateTime2);
echo ($timeOffset/3600);
上面的代码总是给出我不想要的与 UTC 的时间差...我想要两个城市之间精确或接近精确的时差。
N:B:- 举个例子 ASIA/Calcutta - AMERICA/NEW_YORK = - 11 小时(美国比印度晚 11 小时)
最佳答案
获取两个时区的偏移量并将它们相加。
关于php - 当我们有各自地点的当前时间和时区时,两个城市/国家之间的时差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22094368/