我一直在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 - 仅获取 'Date' 之前的秒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10292027/