What is Python's datetime based on?

I know you have Unix, and POSIX time that measure time as the number of seconds that have passed since Thursday 1 January 1970, and Windows NT systems measure time as the number of 100-nanosecond intervals that have passed since 1 January 1601. What I’m use to is ever 1000 nanoseconds being 1 second.

Python uses microseconds which is 1000000 being 1 second. I’m curious to know what python time is base on.

1,000 ns is 1us. 1,000,000,000ns will be 1 second.

Reading the C python source code is your best bet at an answer.
the datetime code is here with an interesting comment: cpython/Modules/_datetimemodule.c at main · python/cpython · GitHub
And the way datetime gets the current time is to call function in pytime.c that end up here: cpython/Python/pytime.c at main · python/cpython · GitHub

1 Like