Reputation: 49
The application already receive the system intent ACTION_TIME_CHANGED. but I need a way to identify if the user advance or delayed date or time.
the scenario is the following:
user's device start with the present date Dec/2022
So, user change date to Dec/2019. (backward date, based on previous date Dec/2022)
Then, user change date to Jan/2020. (forward date, based on previous date Dec/2019)
now, user change date to Jan/2021. (forward date, based on previous date Dec/2020)
again, user change date to Jan/2020. (backward date, based on previous date Dec/2021)
... and so on...
Id like to identify the type of date change (backward or forward) based on the last change, and not from the present date from a web provider.
Upvotes: 0
Views: 61
Reputation: 156
I guess you want to know if the date and time in user's device is true and present in that case you can use a time API to get time from a web provider and compare it to the devices time.
Instant onThisMachine = Instant.now() ;
Instant remote = Instant.parse( stringFromRemoteService ) ;
Duration delta = Duration.between ( remote , onThisMachine ) ;
boolean thisMachineIsBehind = delta.isNegative() ;
These classes are built into Android 26+. For earlier Android, use the latest tooling to access most of the java.time functionality via “API desugaring”.
Upvotes: 1