格林威治時間格式(GMT)與普通時間格式的互相轉換
阿新 • • 發佈:2018-03-15
技術分享 cond body 分享圖片 col inf new 時間 minute
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 = newDate(); 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"))
返回結果:
格林威治時間格式(GMT)與普通時間格式的互相轉換