![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e376. Comparing DatesCalendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25); Calendar newyears = new GregorianCalendar(1999, Calendar.JANUARY, 1); // Determine which is earlier boolean b = xmas.after(newyears); // false b = xmas.before(newyears); // true // Get difference in milliseconds long diffMillis = newyears.getTimeInMillis()-xmas.getTimeInMillis(); // Get difference in seconds long diffSecs = diffMillis/(1000); // 604800 // Get difference in minutes long diffMins = diffMillis/(60*1000); // 10080 // Get difference in hours long diffHours = diffMillis/(60*60*1000); // 168 // Get difference in days long diffDays = diffMillis/(24*60*60*1000); // 7
e374. Creating a Date Object for a Particular Date e375. Determining the Number of Days in a Month e377. Determining a Person's Age e378. Determining If a Year Is a Leap Year e379. Determining the Day-of-Week for a Particular Date
© 2002 Addison-Wesley. |