最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

无法获取 unix 时间戳的时区

网站源码admin46浏览0评论

无法获取 unix 时间戳的时区

无法获取 unix 时间戳的时区

我正在尝试获取 Autralia 的时区并打印一个 unix 时间戳,但是时间戳只是读取 UTC 而不是澳大利亚时间。

这是我正在使用的东西:

//Get todays date
var d = new Date()
//convert to timezone
d.toLocaleString("en-US", {timeZone: "Australia/Sydney"});

const insevendays = Math.floor(new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0,30,0) / 1000 + 604800)
d.toLocaleString("en-US", {timeZone: "Australia/Sydney"});

没有输出正确的时区。

回答如下:

您的问题似乎是您正在

.toLocalString()
上执行函数
d
,但该方法不会编辑原始变量,而是返回一个包含所需时区的新字符串。

要修复您的代码,您可以将变量

d
重新分配给
.toLocalString()
的输出,如下所示:

//Get todays date
var d = new Date()
//convert to timezone
d = d.toLocaleString("en-US", {timeZone: "Australia/Sydney"});

const insevendays = Math.floor(new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0,30,0) / 1000 + 604800)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论