有没有人知道库,函数或API的功能与PHP DateTimeZone :: getLocation - http://php.net/manual/en/datetimezone.getlocation.php相同,但是对于Javascript(或NodeJS NPM)。
请注意,不要只是为了指向正确的方向寻找代码。尝试寻找类似的东西可以找到任何东西。
例如 -
我想采用UTC偏移或时区:
package ajax;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Test")
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
public Test() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
response.getWriter().write("Test_doGet");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
response.getWriter().write("Test_doPost");
}
}
然后根据:
返回位置/地理位置utc_offset: -25200,
time_zone: 'Pacific Time (US & Canada)',
答案 0 :(得分:0)
我决定根据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);
}
?>
答案 1 :(得分:-1)
您可以使用JodaAPI。 http://www.joda.org/joda-time/apidocs/org/joda/time/DateTimeZone.html 希望它有用^^