H
H
Hakito2016-01-19 10:10:51
Java
Hakito, 2016-01-19 10:10:51

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

3 answer(s)
A
Antony, 2016-01-19
@RiseOfDeath

By GPS

A
Antonzm, 2016-01-19
@Antonzm

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мс )

C
Chvalov, 2016-04-01
@Chvalov

Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
String time = sdf.format(cal.getTime());
Log.v("Время: ", time);

developer.android.com/intl/ru/reference/java/util/...
See more answer here - stackoverflow.com/questions/16516888/how-to-get-cu...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question