【发布时间】:2020-06-08 05:14:14
【问题描述】:
我有 IST 日期和时间 - Thu Oct 01 2020 05:30:00 GMT+0530(印度标准时间),我需要根据用户浏览器时区转换该日期时间。 因此,如果我可以从我的日期时间中减去或添加 GMT 值,我可以获得正确的日期时间。 请帮忙。
var newdate = $(this).data("systemdate");
var format = $(this).data("format");
var timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
var tm_short = moment.tz(newdate, timezone).format('z');
var datecoverted = new Date(newdate+" GMT+0530")
var result = moment(datecoverted).format(format);
我已尝试使用上述代码,它在 chrome 中运行良好。但它在 Mozilla Firefox 中显示无效日期。
【问题讨论】:
-
欢迎来到 Stack Overflow。请查看How do I ask a good question。如果您不向我们展示导致问题的代码,我们将无法提供帮助。请编辑您的问题,在 Minimal, Complete, and Verifiable example 中包含 相关 代码以及您已尝试解决问题的摘要,以便我们提供帮助。
-
感谢您更新问题。您能告诉我们您在 Firefox 中遇到的确切错误吗?
-
显示“无效日期”
-
实际上 Mozilla 在我的代码中不支持 'datecoverted' 变量。
-
你为什么不用moment.tz?
标签: javascript datetime