本文主要是介绍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
这篇关于utc时间转换localtime的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!