Reading a datetime string like 2022-04-26T16:49:20.877 UTC #1207
-
I am trying to port some moment code where I read the datetime string "2022-04-26T16:49:20.877 UTC" but I keep getting invalid datetime with the following
I thought it was the UTC but its not just that as I removed it to test. In my code in the browser debugger I get the error explanation: "the input "2022-04-26T16:49:20.877" can't be parsed as format yyyy-MM-ddTHH:mm:ss.SSS" I am running "luxon": "^2.4.0", Any idea what I am doing wrong ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
For debugging this kind of thing, use tokens: [
// snip
{literal: false, val: 'dd'} // <-- this is your "dd"
{literal: false, val: 'h'} // <-- h, :, and m are the expansion of T
{literal: true, val: ':'}
{literal: false, val: 'm'}
{literal: false, val: 'HH'} // <-- this is your HH
// snip
] |
Beta Was this translation helpful? Give feedback.
-
yeah, you want
But UTC is also a valid zone specifier, so you can parse it with DateTime.fromFormat("2022-04-26T16:49:20.877 UTC", "yyyy-MM-dd'T'HH:mm:ss.SSS z").toISO() //=> '2022-04-26T12:49:20.877-04:00' |
Beta Was this translation helpful? Give feedback.
yeah, you want
z
, notZZZZ
. In formatting, ZZZZ means like "Eastern Standard Time" or "British Summer Time". It can't be parsed though, for reasons explained in the zones documentation: