一个人向我建议
If you know the UTC offset then you can pass it and get the time using following function:
function calcTime(city, offset) {
// create Date object for current location
var d = new Date();
// convert to msec
// subtract local time zone offset
// get UTC time in msec
var utc = d.getTime() - (d.getTimezoneOffset() * 60000);
// create new Date object for different city
// using supplied offset
var nd = new Date(utc + (3600000*offset));
// return time as a string
return "The local time for city"+ city +" is "+ nd.toLocaleString();
}
alert(calcTime('Bombay', '+5.5'));
但我知道用户的pc时区如" Asia / Kolkata"或者"欧洲/伦敦"那我怎么能使用任何js库获取日期和时间。 moment.js可以做到这一点,如果是,所以请给我一些moment.js相关代码,我将通过时区ID并获得该时区日期&时间。感谢