我有一个像布巴内斯瓦尔、奥里萨邦、印度这样的地方的格式化地址。我怎样才能得到这个地方的时区,即 php 代码中的“亚洲/加尔各答”?
我可以使用 googlemapapi 得到这个,即首先我从这个地址得到纬度和经度,然后使用这个纬度和经度以及谷歌时区 api key 我在 javascript 中得到时区。
我想要纯 php 代码中的时区。可以吗?
谢谢你
最佳答案
当然可以。尝试使用 file_get_contents()
:
<?php
$url = "https://maps.googleapis.com/maps/api/timezone/json?location=20,85×tamp=1393575206&sensor=false";
$json_timezone = file_get_contents($url);
print_r($json_timezone);
?>
这将打印:
{ "dstOffset" : 0, "rawOffset" : 19800, "status" : "OK", "timeZoneId" : "Asia/Calcutta", "timeZoneName" : "India Standard Time" }
将时间戳替换为当前时间戳或与您想要的日期/时间对应的时间戳。
关于php - 如何在php中获取一个地方的时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22088618/