Android Kotlin / JAVA - get current world time / UTC in seconds since 1970

北战南征 提交于 2021-01-28 03:15:52

问题


As the title says I need the current workd time in seconds since 1970.

This is what I've tried so far:

System.currentTimeMillis()

and

val df = DateFormat.getTimeInstance()
df.setTimeZone(TimeZone.getTimeZone("gmt"))
val gmtTime = df.format(Date())

But both are showing the time which is based on the phone time, so when a user changes the phone time manually it will be affected

Is there a way to get the current workd time in seconds without using an extern API?


回答1:


No, the only way to get time NOT based on device clock is to request it from some Web API service.



来源:https://stackoverflow.com/questions/54405146/android-kotlin-java-get-current-world-time-utc-in-seconds-since-1970

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!