convert python time.time() to java.nanoTime()

3.3k Views Asked by At

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

There are 3 best solutions below

0
On BEST ANSWER

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).

0
On

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.

0
On

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.