-1

In Python 3.7, time_ns() gives epoch timestamp in nanoseconds. How can it be got in 3.6.9? When I use time(), it gives me seconds.

phileoseda
  • 292
  • 1
  • 6
  • 29

1 Answers1

-2

You can't get nanosecond accuracy even using time_ns(). It's better than time(), but still not real nano-second accuracy.

Take a look at PEP-564 (https://www.python.org/dev/peps/pep-0564/#annex-clocks-resolution-in-python) - maybe you can just multiply by 1e9 and get a satisfactory result.

Radek
  • 22
  • 2
  • 1
    `time()` and `time_ns()` are using the same underlying function to get the time. The only difference is that one returns a floating point and the other returns an integer. The precision (of both of them) depends on the operating system. – zvone Dec 08 '20 at 08:25
  • The link that I posted contains a resolution analysis. I suppose you didn't open it, so here is the summary: "The resolution of time.time_ns() is much better than time.time(): 84 ns (2.8x better) vs 239 ns on Linux and 318 us (2.8x better) vs 894 us on Windows." – Radek Dec 08 '20 at 08:42