Get POSIX/Unix time in seconds and nanoseconds in Python?

Since Python 3.7 it’s easy to achieve with time.time_ns()

Similar to time() but returns time as an integer number of nanoseconds since the epoch.

All new features that includes nanoseconds in Python 3.7 release:
PEP 564: Add new time functions with nanosecond resolution

Leave a Comment