最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Luxon is failing to parse this date format - Stack Overflow

programmeradmin4浏览0评论

I'm trying to figure out why luxon is failing to parse this date format.

This is the original value I have: 2019-04-23T23:15:07.910Z.

What format is this (it looks like an iso format).

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 }

I'm trying to figure out why luxon is failing to parse this date format.

This is the original value I have: 2019-04-23T23:15:07.910Z.

What format is this (it looks like an iso format).

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 }
Share Improve this question asked Apr 23, 2019 at 23:38 CatfishCatfish 19.3k60 gold badges213 silver badges358 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 22

Ahh just figured it out. Turns out 2019-04-23T23:15:07.910Z is actually a javascript date object.

This means I needed to do const fromJSDate = DateTime.fromJSDate(document.lastUpdatedAt)

发布评论

评论列表(0)

  1. 暂无评论