Convert Past Real Time to Date

I am writing a simple application to monitor synchronization actions on Android and am stuck with SyncInfo.startTimewhich returns a value based on SystemClock.elapsedRealTime(). How to convert this value to a regular object Date?

+3
source share
1 answer

Found a solution to the problem:

new Date(System.currentTimeMillis() 
       - SystemClock.elapsedRealtime()
       + elapsedTime);

where elapsedTimeis the time I get from Android. As far as I checked, this seems to return the correct date / time for elapsed time. I just do not really like this answer because Google does not recommend using System.currentTimeMillis(). If someone does not have a better answer, I close this question, as was said.

+9
source

Source: https://habr.com/ru/post/1584447/


All Articles