本文介绍了Android Kotlin/JAVA-获取自1970年以来以秒为单位的当前世界时间/UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我需要自1970年以来的当前工作时间(以秒为单位).

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

这是我到目前为止尝试过的:

This is what I've tried so far:

System.currentTimeMillis()

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

有没有一种方法可以在不使用extern API的情况下以秒为单位获取当前工作时间?

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

推荐答案

不,获取不基于设备时钟的时间的唯一方法是从某些Web API服务请求时间.

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

这篇关于Android Kotlin/JAVA-获取自1970年以来以秒为单位的当前世界时间/UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 10:05