gpt4 book ai didi

javascript - Node/Electron : Convert one timezone to the other in website/client side

转载 作者:行者123 更新时间:2023-11-30 14:48:24 26 4
gpt4 key购买 nike

我从 API 收到一个字符串,如下所述:

var time = 2018-01-31T11:11:41+05:30;

现在下一步是我必须将这个时间转换为浏览器(客户端)本地时区。

我正在使用 moment Js 但找不到合适的函数来实现此转换。

最佳答案

您可以简单地使用 moment(String) .

由于您的字符串包含 utc 偏移量,所以它会考虑在内,但它会在本地模式下创建和对象,因为:

By default, moment parses and displays in local time.

这里是一个活生生的例子:

var time = '2018-01-31T11:11:41+05:30';
console.log( moment(time).format() );
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>

关于javascript - Node/Electron : Convert one timezone to the other in website/client side,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48538001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com