A
A
Alexey Nekrasov2018-03-27 19:47:47
Android
Alexey Nekrasov, 2018-03-27 19:47:47

How to compare two dates correctly?

From the server I receive time in timestamp, the last action of the user. The whole point is to determine whether the user is online or not.
Further, judging by the documentation, System.currentTimeMillis() returns the time since January 1, 1970 in milliseconds in UTC, and here the question arises, the time zone should not affect System.currentTimeMillis(), right?

//Получаю timestamp на устройстве
long timestamp = System.currentTimeMillis() / 1000L;

//Время когда пользователь перестанет быть онлайн
long online = latestAct+ 960L;

if(online > timestamp ){
    //Онлайн
} else {
   //Офлайн
}

And in theory everything should work fine, but no. On one device it works fine, on the other it doesn't.
The time is not set correctly on the device. How to perform this action correctly?
PS checked, the device returns unix an hour ahead

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-03-27
@klim76

//Get the timestamp on the device
long timestamp = System.currentTimeMillis() / 1000L;

This thing can give you anything back, can't it?
It would be more correct for the server to answer whether the user is online or not

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question