我需要一个Android应用程序,我需要将当前日期转换为自1970年以来的秒数.
我现在正在做的是这个.
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();
Run Code Online (Sandbox Code Playgroud)
另一个问题是我的应用程序需要在德国运行.因此需要将时间转换为他们的时区,然后将其转换为自1970年以来的秒数.
以上并没有给我正确的结果.
Jea*_*nal 108
System.currentTimeMillis()
给出自Unix纪元(1970年1月1日00:00:00 UTC)以来的毫秒数.
除以1000得到秒数.
//long currentTimeMillis ()-Returns the current time in milliseconds.
long millis = System.currentTimeMillis();
//Divide millis by 1000 to get the number of seconds.
long seconds = millis / 1000;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
45339 次 |
最近记录: |