Answer the question
In order to leave comments, you need to log in
How to know the exact time in android?
I am writing a game for android. I ran into the following problem:
I need the frame to be updated no more than, say, 30 times per second. To do this, I get the time that has passed since the last update.
The problem is that through System.currentTimeMilisec() and System.nanoTime() the time is rounded up to 10 milliseconds, which is quite a lot. How can I get the time to the nearest millisecond?
Answer the question
In order to leave comments, you need to log in
try it differently, I personally do it through a timer, it’s quite convenient, but sometimes expensive (the scene doesn’t change, but it redraws everything again and again)
new Timer().schedule(new TimerTask() {
@Override
public void run() {
loop(); // метод который будет обновляться
}
}, 0, 20); // второй параметр задержка перед вызовами loop(); (этот таймер будет бесконечно вызывать метод loop(); каждые 20мс )
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
String time = sdf.format(cal.getTime());
Log.v("Время: ", time);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question