I have a game that loops. I need to check the current number of milliseconds. I don't want to create a new Date object just to get the number of milliseconds that has passed. Is there a way to get the current time without creating a new Date object every iteration of my game loop?
Example:
Date d = new Date();
while(true)
{
long currentTime = d.getCurrentTime();
}
In the above code, the value of the currentTime variable would continuously change.
Rather than using Date, you can access the static method
long currentTime = System.currentTimeMillis()
This returns the current time of the given system in milliseconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With