简体   繁体   English

Luxon未能解析此日期格式

[英]Luxon is failing to parse this date format

I'm trying to figure out why luxon is failing to parse this date format. 我试图弄清楚为什么luxon无法解析这种日期格式。

This is the original value I have: 2019-04-23T23:15:07.910Z . 这是我的原始值: 2019-04-23T23:15:07.910Z

What format is this (it looks like an iso format). 这是什么格式(它看起来像iso格式)。

Code snippet: 代码段:

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)

Output from snippet above: 上面代码段的输出:

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 }

Ahh just figured it out. 啊,只是想通了。 Turns out 2019-04-23T23:15:07.910Z is actually a javascript date object. 原来2019-04-23T23:15:07.910Z实际上是一个javascript日期对象。

This means I needed to do const fromJSDate = DateTime.fromIJSDate(document.lastUpdatedAt) 这意味着我需要执行const fromJSDate = DateTime.fromIJSDate(document.lastUpdatedAt)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM