【发布时间】:2020-04-16 12:54:42
【问题描述】:
我正在构建对时间敏感的应用程序,即某些任务需要在特定时间内完成。有多种获取时间的方法,即System.currentTimeMillis() 和gpsLocation.getTime()。我不想使用System.currentTimeMillis(),因为用户可以手动更改时间。 gpsLocation.getTime() 呢?我观察到在某些区域,设备无法获取GPS 位置。那我应该使用哪个timestamp?
位置时间戳
open fun onLocationChanged(location: Location?) {
ellapsedTime = location.getTime()
}
我正在检测用户是否使用以下代码更改了自动时间和时区设置:
val isAutoTime = Settings.Global.getInt(activity!!.getContentResolver(), Settings.Global.AUTO_TIME)
val isAutoTimezone = Settings.Global.getInt(activity!!.getContentResolver(), Settings.Global.AUTO_TIME_ZONE)
我应该使用什么方法来获取时间戳?
问题中缺少什么?
请评论缺少的部分是什么?或者您可能不理解问题/疑虑。我正在写比较时间戳的最佳方法。我添加了使用System.currentTimeinMillis() 和location.getTime() 的优缺点。由于应用程序依赖于时间,因此如果用户使用时间设置,那么我应该能够比较准确的时间戳而不是系统时间。
【问题讨论】:
-
@OleV.V.:在问题描述
I don't want to use System.currentTimeMillis() because user can manually change the time中提到了这一点
标签: android android-location android-gps android-date