i need to know tomorrows end date time in milliseconds. to get current datetime in miliseconds we use

long dateTimestamp = System.currentTimeMillis(); // 12/6/2014 7.50 PM

if today date is 12/6/2014 7:50 PM and Tomorrow date is 13/6/2014 and it ends on 11:59 PM. i need this in milliseconds.

有帮助吗?

解决方案

Following is how you get the end of tomorrow -

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);

This should work:

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top