Here is and example of date-time moment of time in ISO 8601 with milliseconds:
2024-03-02T17:13:07.123Z
What is the correct way to write date-time if case the milliseconds part consists not of 3 digits, but from smaller number of digits (the milliseconds part is less than 100 milliseconds).
For example, if the milliseconds number is 15, so 15 milliseconds past the whole second, how the string should be written?
2024-03-02T17:13:07.15Z
or
2024-03-02T17:13:07.015Z
?
And if the milliseconds part is equal to zero there are many possible ways to write it, but what is the correct one to use?
2024-03-02T17:13:07.0Z
or
2024-03-02T17:13:07.Z
or
2024-03-02T17:13:07.000Z
?
Can you please quote the relevant part of the documentation that states how this situation should be handled?
The standard representation is
2024-03-02T17:13:07.015Z.Demo using Java Language:
Output:
Online Demo
The standard representation is
2024-03-02T17:13:07Z.This is where a format removes the ambiguity e.g. if you use
yyyy-MM-dd'T'HH:mm:ss.SSSas the format, your date-time object will be printed as2024-03-02T17:13:07.000Z. A format is just a way to represent an object for a specific use case but a representation does not change the value e.g. you can write5as5.0,5.00,5.000for your specific use case and for every use case, the value will remain5.Demo using Java Language:
Output:
Online Demo
Learn more about the modern date-time API from Trail: Date Time.