【问题标题】:ReactJs - How to convert a current date to ISO 8601 format?ReactJs - 如何将当前日期转换为 ISO 8601 格式?
【发布时间】:2021-07-29 12:03:28
【问题描述】:

在 reactjs 应用程序中,我得到了 2020-04-03T09:22:20.45-04:00 格式的日期。它采用ISO 8601 日期格式

另外我需要将当前日期和时间转换为ISO 8601 格式,我该怎么做?

【问题讨论】:

  • 您可以根据需要使用momentjs.com作为日期格式。
  • 要转换我应该知道哪种格式对吗?在momentjs 我没有得到这种格式。

标签: jquery json reactjs date iso8601


【解决方案1】:

moment().toISOString(); // or format() - see below

http://momentjs.com/docs/#/displaying/as-iso-string/

【讨论】:

    【解决方案2】:

    使用 momentjs 的 ISOString 中的当前日期格式。

    moment().toISOString(new Date());
    

    您还可以使用 momentjs 将日期格式化为您想要的任何格式:

    moment().format();
    

    你应该查看 momentjs 的文档。

    【讨论】:

      猜你喜欢
      • 2017-06-10
      • 2015-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      相关资源
      最近更新 更多