【问题标题】:Get utc offset value from a local timestamp string in nodejs/javascript从 nodejs/javascript 中的本地时间戳字符串获取 utc 偏移值
【发布时间】:2020-05-19 11:18:34
【问题描述】:

我的本​​地时间戳值是以下格式的字符串: '2020-05-19T15:45:07.2306062+05:30'

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

请帮忙。提前致谢

【问题讨论】:

    标签: javascript node.js datetime utc timezone-offset


    【解决方案1】:

    使用以下方法获得偏移量:

    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));
    

    【讨论】:

      猜你喜欢
      • 2021-03-12
      • 2023-01-16
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多