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

King Dingeling :

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?

Maksim Novikov :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=128343&siteId=1