utc时间转换localtime

var time=getTime(timStamp);
 
  
function getTime(timStamp){
    //tim为时间戳,这里timStamp=1453780770000,
    var d = new Date(timStamp);
    //转换为date,d=Tue Jan 26 2016 11:59:30 GMT+0800 (CST)
    var localTime = d.getTime();
    var localOffset = d.getTimezoneOffset() * 60000;
    var utc = localTime + localOffset;
    //根据时区调整时差
    var offset = d.getTimezoneOffset() / 60;

    var now = utc - (3600000*offset);

    var nd = new Date(now);

    //调整显示格式
    var   year=nd.getFullYear();
    var   month=nd.getMonth()+1;
    var   date=nd.getDate();
    var   hour=nd.getHours();
    var   minute=nd.getMinutes();
    var   second=nd.getSeconds();
    return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;

}


输入为:

var time=getTime(1453780770000);
输出为

time= "2016-1-26 12:15:30"


参考网址:

http://www.digitoffee.com/programming/get-local-time-utc-using-moment-js/94/

http://momentjs.com/

http://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time-using-javascript

你可能感兴趣的:(arcgis,api,for,js)