Unix Epoch Millis


#1

This not specifically a rust question, but is something I’m encountering in my rust library.

I’m trying to find out what the expected behaviour should be for a Unix epoch timestamp represented as millis instead of seconds. Is there a standard for millis like there is for seconds?

It looks like a lot of places just append the millis to the end of the seconds format, which is what I’m doing, but for dates before the epoch that would mean the seconds count backwards from 1970 and the millis count forward to it.

Others seem to only read millis if the format is over a certain length.

What I’d really like to know is; what time should a unix millis timestamp of -1 be? 31/12/1969 23:59:59.999 or 31/12/1969 23:59:59.001?


#2

The first. I would find the second very frustrating, because it breaks lexicographic ordering for the time part. More generally the milliseconds should always be between 0 and 999, which requires the seconds part to be the second before the instant in question.


#3

Thanks, that makes sense and is now the way I’m doing things. It was a bit tricky because the date library I’m using takes the milli/nanosecond component separately from the epoch seconds, so it was treated as a different case.

At least I have it consistent now.