Hacker News new | past | comments | ask | show | jobs | submit login

That's an interesting approach, but not without pitfalls. You can't just subtract two timestamps to get a time difference, since there may have been one with 2 billion nanoseconds somewhere in between.



This is true. However:

- You can subtract two SI-based timestamps to get a SI-based time difference. This will give you the correct number of nanoseconds.

- You can subtract two UTC-based timestamps to get a UTC-based time difference. This will not give you a number of nanoseconds.

Note that, if you have a list of when leap seconds are, then you can convert between SI-based and UTC-based timestamps which are counted from the epoch; in this way it is possible to get a SI-based time difference from UTC-based timestamps if you need it.

It is not as simple as just subtracting them of course, but if your application is meant to use precise time differences then you can just use SI-based timestamps instead of UTC-based timestamps, so that you can simply subtract them from each other. Programs that need to deal with days and calendars instead, are likely to prefer to use UTC-based timestamps instead.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: