【问题标题】:set date to a specific timezone in html将日期设置为 html 中的特定时区
【发布时间】:2018-05-10 06:11:36
【问题描述】:

我正在使用

<input id="123" type="date" name="date1">

我知道这将使用默认的本地时间。有没有办法可以将它实际设置为具有特定时区的时间? 例如,我的本地时区是 PST,但我希望此输入以 CST 时间显示时间。 我一直在寻找答案,但仍然没有运气。

【问题讨论】:

    标签: javascript html datetime calendar timezone


    【解决方案1】:

    您可以使用 moment.js。 将 moment.js 附加到您的 html 文件后使用以下函数。 通过 datezone。 你可以从https://momentjs.com/获取 moment.js

    function toTimeZone(time, zone) {
        var format = 'YYYY/MM/DD HH:mm:ss ZZ';
        return moment(time, format).tz(zone).format(format);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-09
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 2021-09-12
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      • 2020-01-01
      相关资源
      最近更新 更多