【问题标题】:Set CET timezone with toISOString()使用 toISOString() 设置 CET 时区
【发布时间】:2021-02-25 15:47:58
【问题描述】:

如何使用 toISOString() 将 MYSQL 时间戳日期更改为 JS 日期并将时区设置为 CET? 这是我使用的,它返回以下格式“2021-02-251 15:27:20”,这是我想要的,只有时间应该是 +1 小时“2021-02-251 16:27:20”:

registration_date_customer.toISOString().replace(/T/, ' ').replace(/\..+/, '')

数据库上的时间是正确的 (16:27:20)。 有谁知道如何设置 CET 时区?

【问题讨论】:

    标签: javascript mysql node.js timestamp


    【解决方案1】:

    您可以使用Date.localeString() 格式化正确的时区,IANA 时区“欧洲/巴黎”相当于 CET。使用“sv”语言环境将产生一个 ISO 格式的字符串(瑞典使用 ISO 日期格式)。

    const registration_date_customer = new Date("2021-02-25 15:27:20Z");
    console.log(registration_date_customer.toLocaleString("sv", { timeZone: "Europe/Paris"}));
       

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-07
      • 2012-06-05
      • 2018-05-31
      • 2019-08-10
      • 2021-08-15
      • 1970-01-01
      • 2021-12-19
      • 2022-01-21
      相关资源
      最近更新 更多