我需要知道明天结束日期的时间,以毫秒为单位。要获得以毫秒为单位的当前日期时间,我们使用
long dateTimestamp = System.currentTimeMillis(); // 12/6/2014 7.50 PM
如果今天的日期是12/6/2014 7:50 PM,明天的日期是13/6/2014,结束于11:59 PM。我需要在几毫秒内完成。
你如何得到明天的结束-
Calendar cal = Calendar.getInstance(); //current date and time
cal.add(Calendar.DAY_OF_MONTH, 1); //add a day
cal.set(Calendar.HOUR_OF_DAY, 23); //set hour to last hour
cal.set(Calendar.MINUTE, 59); //set minutes to last minute
cal.set(Calendar.SECOND, 59); //set seconds to last second
cal.set(Calendar.MILLISECOND, 999); //set milliseconds to last millisecond
long millis = cal.getTimeInMillis();
long currentTime = System.currentTimeMillis();
long endOfTomorrow = currentTime + DateUtils.DAY_IN_MILLIS
+ (DateUtils.DAY_IN_MILLIS - currentTime % DateUtils.DAY_IN_MILLIS);
应该可以:
Calendar calendar = new GregorianCalendar();
calendar.setTime(dateTimestamp);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.add(Calendar.DATE, 1);
calendar.getTime(); // retrieves msec time of the time set in calendar