相差3600秒的时间戳,转成时间格式后是同一个时间
两个时间戳:1541318400000和1541322000000,在电脑时间是西7区,西雅图时间的时候,格式化后的时间是一样的。
index.js
const app = getApp() Page({ data: { msg: '' , timestamp1: 1541318400000, timestamp2: 1541322000000, formated1: '' , formated2: '' }, onLoad: function () { var myTimezone = new Date().getTimezoneOffset(); console.log(myTimezone); var msg = '' ; if (myTimezone != 420){ msg = '请设置电脑时区为西7区,西雅图时间' ; } this .setData({ msg: msg, formated1: this .formatDateTime( this .data.timestamp1), formated2: this .formatDateTime( this .data.timestamp2), }); }, formatDateTime: function (inputTime) { var date = new Date(inputTime); var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ( '0' + m) : m; var d = date.getDate(); d = d < 10 ? ( '0' + d) : d; var h = date.getHours(); h = h < 10 ? ( '0' + h) : h; var minute = date.getMinutes(); var second = date.getSeconds(); minute = minute < 10 ? ( '0' + minute) : minute; second = second < 10 ? ( '0' + second) : second; var str = m + '月' + d + '日 ' + h + ":" + minute + ":" + second; return str; } }) |
index.wxml
< view >{{msg}}</ view > < view >{{timestamp1}} - {{formated1}}</ view > < view >{{timestamp2}} - {{formated2}}</ view > |
运行截图: