php中如何获取某个地方的时区

Sat*_*aty 3 php timezone google-maps-api-3

我有一个像布巴内斯瓦尔,奥里萨邦,印度这样的地方的格式化地址。我怎样才能在php代码中获得这个地方的时区,即“亚洲/加尔各答”?

我可以使用 googlemapapi 得到这个,即首先我从这个地址获取纬度和经度,并使用这个纬度和经度以及谷歌时区 api 密钥我在 javascript 中获取时区。

我想要纯 php 代码中的时区。我可以吗 ?

感谢 Avd

MrU*_*own 5

你当然可以。尝试使用file_get_contents()

<?php
$url = "https://maps.googleapis.com/maps/api/timezone/json?location=20,85&timestamp=1393575206&sensor=false";
$json_timezone = file_get_contents($url);
print_r($json_timezone);
?>
Run Code Online (Sandbox Code Playgroud)

这将打印:

{ "dstOffset" : 0, "rawOffset" : 19800, "status" : "OK", "timeZoneId" : "Asia/Calcutta", "timeZoneName" : "India Standard Time" }
Run Code Online (Sandbox Code Playgroud)

将时间戳替换为当前时间戳或与所需日期/时间对应的时间戳。