Here you can find the source of getRemainingTimeToday(final TimeUnit timeUnit)
public static long getRemainingTimeToday(final TimeUnit timeUnit)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.concurrent.TimeUnit; public class Main { public static long getRemainingTimeToday(final TimeUnit timeUnit) { Calendar todayEnd = Calendar.getInstance(); todayEnd.set(Calendar.HOUR_OF_DAY, 23); todayEnd.set(Calendar.MINUTE, 59); todayEnd.set(Calendar.SECOND, 59); long durationMills = todayEnd.getTimeInMillis() - System.currentTimeMillis(); return millisecondsTo(durationMills, timeUnit); }// w w w. j a v a2 s. co m public static long millisecondsTo(long milliseconds, final TimeUnit timeUnit) { switch (timeUnit) { case MILLISECONDS: return TimeUnit.MILLISECONDS.toMillis(milliseconds); case NANOSECONDS: return TimeUnit.MILLISECONDS.toNanos(milliseconds); case MICROSECONDS: return TimeUnit.MILLISECONDS.toMicros(milliseconds); case SECONDS: return TimeUnit.MILLISECONDS.toSeconds(milliseconds); case MINUTES: return TimeUnit.MILLISECONDS.toMinutes(milliseconds); case HOURS: return TimeUnit.MILLISECONDS.toHours(milliseconds); case DAYS: return TimeUnit.MILLISECONDS.toDays(milliseconds); default: throw new IllegalArgumentException(); } } }