使用jquery以UTC 11:30,0格式获取浏览器时区

时间:2013-03-05 06:39:10

标签: jquery

任何人都建议我使用jquery以'UTC +11:30,0'格式获取浏览器时区,因为我想在我的数据库中仅存储'UTC +11:30,0'

1 个答案:

答案 0 :(得分:0)

<强> CHECK THIS...

function calcTime(city, offset) {
    // create Date object for current location
    var d = new Date();

    // convert to msec
    // add 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'));