5

java's System.nanoTime() seems to give a long: 1337203874231141000L while python time.time() will give something like 1337203880.462787

how can i convert time.time()'s value to something match up to System.nanoTime()?

3 Answers3

6

You can't.

From the documentation:

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative).

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
0

Divide the output of System.nanoTime() by 10^9. This is because it is in nanoseconds, while the output of time.time() is in seconds.

Hank Gay
  • 70,339
  • 36
  • 160
  • 222
0

Python documentation indicates that the time is epoch based in python. Java does as well. The problem is that python uses a float/double for time, while java uses an int.

I think it would be easier to convert to a standard format, then convert to the target system, rather then try to use the number of seconds since the epoch as you're trying to do.

Jim Barrows
  • 3,634
  • 1
  • 25
  • 36