TimeUnit.MILLISECONDS : TimeUnit « java.util.concurrent « Java by API






TimeUnit.MILLISECONDS

 


import java.util.Calendar;
import java.util.concurrent.TimeUnit;

public class Main {

  public static long getDifference(Calendar a, Calendar b, TimeUnit units) {
    return units.convert(b.getTimeInMillis() - a.getTimeInMillis(), TimeUnit.MILLISECONDS);
  }

  public static void main(String[] args) {
    Calendar first = Calendar.getInstance();
    first.set(2008, Calendar.AUGUST, 1);
    Calendar second = Calendar.getInstance();

    System.out.println(getDifference(first, second, TimeUnit.DAYS) + " day(s) between ");
  }
}

   
  








Related examples in the same category

1.TimeUnit: DAYS
2.TimeUnit.SECONDS
3.TimeUnit: sleep(long timeout)
4.TimeUnit: toDays(long duration)
5.TimeUnit: toHours(long duration)
6.TimeUnit: toMinutes(long duration)