【问题标题】:Formatting Standard time to ISO 8601 with Electron/NodeJS using Moment使用 Moment 使用 Electron/NodeJS 将标准时间格式化为 ISO 8601
【发布时间】:2021-01-19 07:00:45
【问题描述】:

我正在尝试使用 Moment.js 将标准时间 October 3, 2020, 9:24 pm 转换为 ISO 时间,但不幸的是,我一直收到“无效日期”。我有一个格式化为标准时间的日期选择器表单。

这是代码 var OutputISO = moment($("#DatePicker").val());

【问题讨论】:

    标签: javascript jquery node.js electron momentjs


    【解决方案1】:

    不需要额外的库来将标准时间转换为 ISO 格式,以下表达式应该“开箱即用”:

    new Date('October 3, 2020, 9:24 pm').toISOString()
    // -> "2020-10-03T19:24:00.000Z"
    

    参考:Date.prototype.toISOString()

    因此,这行代码也应该返回正确的字符串,除非表单元素 ID 存在问题:

    let OutputISO = document.getElementById('DatePicker').toISOString();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-05
      • 2021-04-12
      相关资源
      最近更新 更多