For time layouts, if the fractional seconds are optional, use
9 instead of
0 in the layout. For example,
2006-01-02T15:04:05.00000Z matches only times with 5 digits after the decimal place. However,
2006-01-02T15:04:05.9Z matches a time with any number of digits after the decimal, including zero.
The Time.Format documentation provides examples, the last one of which explains this behavior.