1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/* Compare date time using before method of Java Calendar This example shows how to compare two calendar objects having different date and time using before method of Java Calendar class. */ import java.util.Calendar; public class CompareDateTimesUsingBefore { public static void main(String[] args) { //create first Calendar object Calendar old = Calendar.getInstance(); //set it to some old date old.set(Calendar.YEAR, 1990); //create second Calendar object Calendar now = Calendar.getInstance(); /* * To compare two different Calendar objects, use * boolean before(Caledar anotherCal) method. * * If the first Calendar object's date and time is before * anotherCal date and time, * it returns true, false otherwise. */ System.out.println("Is old before now ? : " + old.before(now)); } } /* Output would be Is old before now ? : true */ |
hi am getting answers form this page it so interseting at all i don’t even want to leave thank you a lot.