I have the need for extremely precise and accurate time with as few garbage collections (GCs) as possible, ideally 1 per day. System.currentTimeMillis()
is not precise enough, System.nanoTime()
isn't an accurate source of time. The only thing that will give me what I want is java.util.Date.getTime()
but it's not a static method so I have to create a new Date
object every time I need precise and accurate time which causes GC to be triggered more often.
Does anyone know how the Date
class gets accurate and precise time? I'm hoping to take Date's method and tailor it to minimize object creation. To summarize my problem, see the following:
long nanosSinceEpoch;
nanosSinceEpoch = System.currentTimeMillis(); // Not precise
nanosSinceEpoch = System.nanoTime(); // Not accurate
nanosSinceEpoch = new Date().getTime(); // Too many objects
EDIT:
I'm not sure why I thought System.currentTimeMillis()
and new Date().getTime()
were different but it turns out they are the same. But that didn't fix my problem sadly.
Also, getNano()
from java.time.Instant
appears to only have millisecond resolution.