格林威治时间格式(GMT)与普通时间格式的互相转换


GMT --> 普通时间格式:

方法:

function GMTToStr(time){
    var date = new Date(time)
    var Str=date.getFullYear() + '-' +
    (date.getMonth() + 1) + '-' + 
    date.getDate() + ' ' + 
    date.getHours() + ':' + 
    date.getMinutes() + ':' + 
    date.getSeconds()
    return Str
}

 

调用:

var today = new Date();
console.log(GMTToStr(today));

 

返回结果:

 

 

普通时间格式 --> GMT:

方法:

function StrToGMT(time){
    var GMT = new Date(time)
    return GMT
}

 

调用:

console.log(this.StrToGMT("2018-3-15 17:55:47"))

 

返回结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM