Javascript Timezone获取位置类似于PHP DateTimeZone::getLocation
Javascript Timezone get Location similar to PHP DateTimeZone::getLocation?
是否有人知道一个库,函数或API的功能与PHP DateTimeZone::getLocation - http://php.net/manual/en/datetimezone.getlocation.php相同,但用于Javascript(或NodeJS NPM)。
请注意,不要寻找代码只是为了指出我在正确的方向。试着寻找类似的东西可以找到任何东西。
例如-
我想取UTC偏移量或时区:
utc_offset: -25200,
time_zone: 'Pacific Time (US & Canada)',
然后在此基础上返回位置/地理位置:
country_code: CZ
latitude: 50.08333
longitude: 14.43333
由于时间紧迫,我决定制作一个基于PHP DateTimeZone::getLocation函数的小API。我可能会在稍后的阶段将其作为公共API。
这里是gitHub下载也:https://github.com/sputn1k/timezoneGetLocationAPI/
<?php
//usage: /?timezone=Europe/Prague
//output(JSON): {"country_code":"CZ","latitude":50.08333,"longitude":14.43333,"comments":""}
if(isset($_GET['timezone'])) {
$timezone = $_GET['timezone'];
try {
$timezone = new DateTimeZone($timezone);
output(timezone_location_get($timezone));
} catch(Exception $error) {
output(array('error' => 'bad timezone')); //or add $error for full message
}
}
function output($data){
echo json_encode($data);
}
?>
您可以使用JodaAPI。http://www.joda.org/joda-time/apidocs/org/joda/time/DateTimeZone.html希望有帮助^^
相关文章:
- 将属性附加到KmlPlacemark GE插件
- Google Place 自动完成功能会在下拉列表中的结果(预测)中显示“street_number”,但不会在 .ge
- setRequestHeader 不起作用,我想设置我的标头,然后在 Amazon EC2 中的 ajax 中发出 GE
- feature.getId() 在使用 ge.parseKml() 加载时返回 null
- Ge 在 Wordpress 中的帖子 ID 在 category.php.
- 在GE插件中使用NetworkLinkControl进行更新
- DateTime和DateTimeZone的奇怪行为
- 即使在注入http之后,Uncaught TypeError: Cannot read property 'ge
- JavaScript - WebAudio API ScriptProcessorNode InputBuffer ge
- 查询dynamoDB的关键条件'GE'在哈希键上
- 为什么返回对象是由文档.getElementById不同于$(".class").last().ge
- Javascript Timezone获取位置类似于PHP DateTimeZone::getLocation