首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Luxon无法解析此日期格式

Luxon无法解析此日期格式
EN

Stack Overflow用户
提问于 2019-04-24 07:38:54
回答 1查看 2.7K关注 0票数 1

我正在尝试找出为什么luxon无法解析这种日期格式。

这是我拥有的原始值:2019-04-23T23:15:07.910Z

这是什么格式(看起来像iso格式)。

代码片段:

console.log('document.lastUpdatedAt = ', document.lastUpdatedAt)

const fromISO = DateTime.fromISO(document.lastUpdatedAt)
console.log('fromISO = ', fromISO)

const fromSQL = DateTime.fromSQL(document.lastUpdatedAt)
console.log('fromSQL = ', fromSQL)

const fromHTTP = DateTime.fromHTTP(document.lastUpdatedAt)
console.log('fromHTTP = ', fromHTTP)

以上代码片段的输出:

document.lastUpdatedAt =  2019-04-23T23:15:07.910Z
test =  test
fromISO =  DateTime {
  ts: 1556062543882,
  _zone: LocalZone {},
  loc:
   Locale {
     locale: 'en',
     numberingSystem: null,
     outputCalendar: null,
     intl: 'en',
     weekdaysCache: { format: {}, standalone: {} },
     monthsCache: { format: {}, standalone: {} },
     meridiemCache: null,
     eraCache: {},
     specifiedLocale: null,
     fastNumbersCached: null },
  invalid:
   Invalid {
     reason: 'unparsable',
     explanation:
      'the input "Tue Apr 23 2019 16:15:07 GMT-0700 (Pacific Daylight Time)" can\'t be parsed as ISO 8601' },
  weekData: null,
  c: null,
  o: null,
  isLuxonDateTime: true }
fromSQL =  DateTime {
  ts: 1556062543889,
  _zone: LocalZone {},
  loc:
   Locale {
     locale: 'en',
     numberingSystem: null,
     outputCalendar: null,
     intl: 'en',
     weekdaysCache: { format: {}, standalone: {} },
     monthsCache: { format: {}, standalone: {} },
     meridiemCache: null,
     eraCache: {},
     specifiedLocale: null,
     fastNumbersCached: null },
  invalid:
   Invalid {
     reason: 'unparsable',
     explanation:
      'the input "Tue Apr 23 2019 16:15:07 GMT-0700 (Pacific Daylight Time)" can\'t be parsed as SQL' },
  weekData: null,
  c: null,
  o: null,
  isLuxonDateTime: true }
fromHTTP =  DateTime {
  ts: 1556062543890,
  _zone: LocalZone {},
  loc:
   Locale {
     locale: 'en',
     numberingSystem: null,
     outputCalendar: null,
     intl: 'en',
     weekdaysCache: { format: {}, standalone: {} },
     monthsCache: { format: {}, standalone: {} },
     meridiemCache: null,
     eraCache: {},
     specifiedLocale: null,
     fastNumbersCached: null },
  invalid:
   Invalid {
     reason: 'unparsable',
     explanation: 'the input "[object Object]" can\'t be parsed as HTTP' },
  weekData: null,
  c: null,
  o: null,
  isLuxonDateTime: true }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-24 07:52:12

啊,刚刚想明白了。事实证明,2019-04-23T23:15:07.910Z实际上是一个javascript date对象。

这意味着我需要做const fromJSDate = DateTime.fromIJSDate(document.lastUpdatedAt)

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55820775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档