Question

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()?

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top