Javascript 时区获取位置类似于 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)',
然后 return 位置/地理位置基于:
country_code: CZ
latitude: 50.08333
longitude: 14.43333
您可以使用 JodaAPI。
http://www.joda.org/joda-time/apidocs/org/joda/time/DateTimeZone.html
希望对你有帮助^^
由于时间紧迫,我决定基于 PHP DateTimeZone::getLocation 函数制作一个小的 API。我可能会在稍后阶段将其设为 Public 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);
}
?>
有谁知道一个库、函数或 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)',
然后 return 位置/地理位置基于:
country_code: CZ
latitude: 50.08333
longitude: 14.43333
您可以使用 JodaAPI。 http://www.joda.org/joda-time/apidocs/org/joda/time/DateTimeZone.html 希望对你有帮助^^
由于时间紧迫,我决定基于 PHP DateTimeZone::getLocation 函数制作一个小的 API。我可能会在稍后阶段将其设为 Public 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);
}
?>