2

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?

King Dingeling
  • 177
  • 1
  • 2
  • 16
  • 2
    "without using an extern API" you're going to need to talk to *something*. – Andy Turner Jan 28 '19 at 15:26
  • But what is android using to set the current time automatically? So far I used an extern API but there was trouble since the latest patch which I fixed. But I don't want to worry with every damn android update so I want to use as few APIs as possible in general – King Dingeling Jan 28 '19 at 15:31
  • 1
    @KingDingeling That would be a [Network Time Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) server, which would be an external resource. Otherwise a phone is reliant on its internal clock, which as you mentioned can be changed. – Michael Dodd Jan 28 '19 at 15:33
  • 1
    See [How to get current time from internet in android](https://stackoverflow.com/questions/13064750/how-to-get-current-time-from-internet-in-android). Search for more similar questions and answers. – Ole V.V. Jan 28 '19 at 16:00

1 Answers1

5

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

Maksim Novikov
  • 835
  • 6
  • 18