本文介绍了如何获得自1970年以来通过的日期值的秒数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序中,我需要当前的日期要转换为自1970年以来经过的秒数。

i have to an android application in which i need to covert the current date to the number of seconds passed since 1970.

我在做什么目前是这样的。

What i am doing currently is this.

Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        cal.set(currentDate.get(Calendar.YEAR), month,
            currentDate.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
long timesince1970 = cal.getTime().getTime();

另一个问题是,我的应用程序需要在德国运行。因此,有必要将时间转换为自己的时区,然后将其转换成秒数自1970年以来

Another problem is that my application needs to run in germany. Hence the need to convert the time to their timezone and then convert it to the number of seconds since 1970.

以上是没有给我正确的结果。

The above is not giving me correct results.

推荐答案

<$c$c>System.currentTimeMillis()让你从unix新纪元的毫秒数(1970年1月1日00:00:00 UTC)。

System.currentTimeMillis() gives you the number of milliseconds since the Unix epoch (January 1, 1970 00:00:00 UTC).

除以1000就得到秒数。

Divide it by 1000 to get the number of seconds.

这篇关于如何获得自1970年以来通过的日期值的秒数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 10:05