在nodejsjavascript中从本地时间戳字符串中获取utc偏移值。

问题描述 投票:-3回答:1

我的本地时间戳值是一个字符串,格式如下:'2020-05-19T15:45:07.2306062+05:30'。

如何使用nodejsjavascript从这种格式的日期字符串中获取UTC偏移值?

请帮助我。先谢谢你

javascript node.js datetime utc timezone-offset
1个回答
0
投票

用下面的方法得到偏移值。

var trimmedDate = '2020-05-19T20:16:56.2306062+05:30'.slice(0,-6)
var localtimestamp = new Date(trimmedDate)
var difference = new Date()-localtimestamp;
var offset = Math.trunc(difference/(1000*60));
© www.soinside.com 2019 - 2024. All rights reserved.