Closed codingfabi closed 1 year ago
the ISO 8601 definition does not consider milliseconds
I am not sure where you got this information. The Wikipedia article you linked specifically states that:
A decimal fraction may be added to the lowest order time element present in any of these representations. A decimal mark, either a comma or a dot, is used as a separator between the time element and its fraction.
This is exactly what Luxon does when ISO-formatting a timestamp with sub-second components (i.e. milliseconds):
console.log(DateTime.fromObject({milliseconds: 300}).toISO());
Outputs: "2023-02-20T12:20:46.300+01:00"
You can suppress the output of the milliseconds (if there aren't any, which you can ensure using startOf('second')
) by using toISO({suppressMilliseconds: true})
.
I am not sure where you got this information. The Wikipedia article you linked specifically states that:
The wikipedia entry for ISO8601 shows the datestring without milliseconds, thats why I assumed the stringified ISO dates would be shown without sub-seconds aswell:
You can suppress the output of the milliseconds (if there aren't any, which you can ensure using
startOf('second')
) by usingtoISO({suppressMilliseconds: true})
.
Yeah thank you, this is all I needed :) Closing this as it does not require any actions.
When formatting a date with the
toIso()
function, the resulting date contains milliseconds even though the ISO 8601 definition does not consider milliseconds ( seen here https://en.wikipedia.org/wiki/ISO_8601).I found this issue: #253 where I could see that milliseconds in the ISO format were purposefully implemented. However, I either do not understand the reason or would argue that even though fractional seconds are not cut from the ISO date, they should not be part of the displayed string.
So I would assume two ways to approach this:
toISO()
as it is technically not conform with the ISO definition.toISOString()
function that cuts the milliseconds.I'm also happy if this is not implemented but would be really interested in the reason for the necessity of the miliseconds :)