简体   繁体   English

在Android系统中,对于日期和时间的每一次变化,有没有办法知道用户是否提前或延迟了设备时间或日期?

[英]In Android system, for every change in date and time, is there a way to know if the user has advanced or delayed the device time or date?

The application already receive the system intent ACTION_TIME_CHANGED.应用程序已经收到系统意图 ACTION_TIME_CHANGED。 but I need a way to identify if the user advance or delayed date or time.但我需要一种方法来确定用户是提前还是延迟日期或时间。

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.我想您想知道用户设备中的日期和时间是否真实并存在,在这种情况下,您可以使用时间 API 从 web 提供商处获取时间并将其与设备时间进行比较。

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+.这些类内置于 Android 26+。 For earlier Android, use the latest tooling to access most of the java.time functionality via “API desugaring”.对于早期的 Android,使用最新的工具通过“API 脱糖”访问大部分java.time功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM