我一直在Android上的一个应用程序上工作,我必须从纪元到日期获取秒数...通常在使用以下功能时

long timeInSeconds = System.currentTimeMillis()/1000;


它向我返回直到当前时间(包括日期和时间)的秒数。我实际上想忽略秒的时间部分,并保持秒数直到日期,这将导致当天的时间戳相同……无论如何都可以这样做。任何帮助表示赞赏。

最佳答案

Calendar timeLessCalendar = Calendar.getInstance()
timeLessCalendar.set(Calendar.HOUR_OF_DAY,0);
timeLessCalendar.set(Calendar.MINUTE,0);
timeLessCalendar.set(Calendar.SECOND,0);
timeLessCalendar.set(Calendar.MILLISECOND,0);
//now grab the seconds
long secondTillDate =  timeLessCalendar.getTime().getTime()/1000;

关于java - 直到“日期”才获得秒数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10292027/

10-09 07:04