我想在javascript中得到不同时区的两个时间戳的差值:
var firstTime ="2017-07-21 04:34:21";
var timeZone1:"+0100";
var secondTime ="2017-07-21 04:36:27";
var timeZone2:"+0124"; 我们如何才能得到毫秒级的差值?
发布于 2017-07-25 14:23:06
将字符串转换为ISO 8601格式。这些方法通常在JavaScript Date构造函数中工作得很好。然后简单地从另一个中减去一个
var firstTime ="2017-07-21T04:34:21";
var timeZone1 = "+01:00";
var secondTime = "2017-07-21T04:36:27";
var timeZone2 = "+01:24";
const firstDate = new Date(firstTime + timeZone1)
const secondDate = new Date(secondTime + timeZone2)
console.log('firstDate', firstDate)
console.log('secondDate', secondDate)
console.info('diff', firstDate - secondDate)
发布于 2017-07-25 14:24:40
您可以使用moment.js (https://momentjs.com/)来获取不同时区的当前时间戳。
但别忘了:“时区!=偏移”https://stackoverflow.com/tags/timezone/info
https://stackoverflow.com/questions/45295096
复制相似问题