gpt4 book ai didi

javascript - dayjs 没有正确转换时区

转载 作者:行者123 更新时间:2023-12-04 16:39:33 69 4
gpt4 key购买 nike

我正在尝试将日期从本地时间(台北 UTC+8)转换为洛杉矶(UTC-7)
但是 dayjs 转换似乎完全关闭:

dayjs("2020-09-21 20:30").tz("Asia/Taipei")
这导致 2020 年 9 月 22 日星期二 05:30:00 GMT-0400(东部夏令时间)但它应该是
2020 年 9 月 21 日星期一 02:30:00 GMT-0400(东部夏令时间)
知道发生了什么吗?

最佳答案

我使用 utc 进行了修复首先,然后在本地时区格式化

import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import tz from 'dayjs/plugin/timezone'

dayjs.extend(utc)
dayjs.extend(tz)

const timeZone = dayjs.tz.guess()
dayjs.utc(utcDate).tz(timeZone)

关于javascript - dayjs 没有正确转换时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64006977/

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