In which we synchronize computers
with the rest of the world.
- You can count the cycles of any regular phenomenon to keep time. Physics is very helpful here.
- Unix time is a useful way to represent time in code. It is (roughly) the number of seconds since the beginning of 1970.
- Python's time.time() checks the Unix time. Beware time zones and leap seconds.
- time.monotonic() taps into an accurate monotonic clock that works beautifully for timing code.
- time.sleep() is conservative tool for pausing your code. It never undersleeps, but always oversleeps just a bit.
- These tools can be used to construct a pacemaker for keeping repetitive code executing on a strict cadence.
1. Online Unix time converter:
3. Python's time module:
4. List of UTC Offsets (Wikipedia):
5. Sedat Kapanoğlu. Street Coder: The Rules to Break and How to Break Them.
Manning, 2021. ISBN:9781617298370
6. Aleksey Shipilёv. Nanotrusting the Nanotime. Last updated 2014-09-28.
7. From the Python 3.11 documentation for time.time():
On Unix, time.sleep() now uses the clock_nanosleep() or nanosleep() function, if available, which has a resolution of 1 nanosecond (10-9 seconds), rather than using select() which has a resolution of 1 microsecond (10-6 seconds). (Contributed by Benjamin Szőke and Victor Stinner in bpo-21302.)
On Windows 8.1 and newer, time.sleep() now uses a waitable timer based on high-resolution timers which has a resolution of 100 nanoseconds (10-7 seconds). Previously, it had a resolution of 1 millisecond (10-3 seconds). (Contributed by Benjamin Szőke, Dong-hee Na, Eryk Sun and Victor Stinner in bpo-21302 and bpo-45429.)