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:
JavaScript
x
11
11
1
console.log('document.lastUpdatedAt = ', document.lastUpdatedAt)
2
3
const fromISO = DateTime.fromISO(document.lastUpdatedAt)
4
console.log('fromISO = ', fromISO)
5
6
const fromSQL = DateTime.fromSQL(document.lastUpdatedAt)
7
console.log('fromSQL = ', fromSQL)
8
9
const fromHTTP = DateTime.fromHTTP(document.lastUpdatedAt)
10
console.log('fromHTTP = ', fromHTTP)
11
Output from snippet above:
JavaScript
1
74
74
1
document.lastUpdatedAt = 2019-04-23T23:15:07.910Z
2
test = test
3
fromISO = DateTime {
4
ts: 1556062543882,
5
_zone: LocalZone {},
6
loc:
7
Locale {
8
locale: 'en',
9
numberingSystem: null,
10
outputCalendar: null,
11
intl: 'en',
12
weekdaysCache: { format: {}, standalone: {} },
13
monthsCache: { format: {}, standalone: {} },
14
meridiemCache: null,
15
eraCache: {},
16
specifiedLocale: null,
17
fastNumbersCached: null },
18
invalid:
19
Invalid {
20
reason: 'unparsable',
21
explanation:
22
'the input "Tue Apr 23 2019 16:15:07 GMT-0700 (Pacific Daylight Time)" can't be parsed as ISO 8601' },
23
weekData: null,
24
c: null,
25
o: null,
26
isLuxonDateTime: true }
27
fromSQL = DateTime {
28
ts: 1556062543889,
29
_zone: LocalZone {},
30
loc:
31
Locale {
32
locale: 'en',
33
numberingSystem: null,
34
outputCalendar: null,
35
intl: 'en',
36
weekdaysCache: { format: {}, standalone: {} },
37
monthsCache: { format: {}, standalone: {} },
38
meridiemCache: null,
39
eraCache: {},
40
specifiedLocale: null,
41
fastNumbersCached: null },
42
invalid:
43
Invalid {
44
reason: 'unparsable',
45
explanation:
46
'the input "Tue Apr 23 2019 16:15:07 GMT-0700 (Pacific Daylight Time)" can't be parsed as SQL' },
47
weekData: null,
48
c: null,
49
o: null,
50
isLuxonDateTime: true }
51
fromHTTP = DateTime {
52
ts: 1556062543890,
53
_zone: LocalZone {},
54
loc:
55
Locale {
56
locale: 'en',
57
numberingSystem: null,
58
outputCalendar: null,
59
intl: 'en',
60
weekdaysCache: { format: {}, standalone: {} },
61
monthsCache: { format: {}, standalone: {} },
62
meridiemCache: null,
63
eraCache: {},
64
specifiedLocale: null,
65
fastNumbersCached: null },
66
invalid:
67
Invalid {
68
reason: 'unparsable',
69
explanation: 'the input "[object Object]" can't be parsed as HTTP' },
70
weekData: null,
71
c: null,
72
o: null,
73
isLuxonDateTime: true }
74
Advertisement
Answer
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)