List of usage examples for java.util Calendar after
public boolean after(Object when)
Calendar
represents a time after the time represented by the specified Object
. From source file:Main.java
public static void main(String[] args) { Calendar future = Calendar.getInstance(); future.set(Calendar.YEAR, 3010); Calendar now = Calendar.getInstance(); System.out.println("Is futureCal after now ? : " + future.after(now)); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyy"); Date date1 = sdf.parse("Thu Oct 03 07:47:22 2015"); Date date2 = sdf.parse("Mon Jul 05 08:47:22 2015"); System.out.println(sdf.format(date1)); System.out.println(sdf.format(date2)); Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(date1);//from w w w . j a v a 2 s.co m cal2.setTime(date2); if (cal1.after(cal2)) { System.out.println("Date1 is after Date2"); } if (cal1.before(cal2)) { System.out.println("Date1 is before Date2"); } if (cal1.equals(cal2)) { System.out.println("Date1 is equal Date2"); } }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Calendar future = Calendar.getInstance(); System.out.println("Current date: " + cal.getTime()); future.set(Calendar.YEAR, 2015); System.out.println("Year is " + future.get(Calendar.YEAR)); Date time = future.getTime(); if (future.after(cal)) { System.out.println("Date " + time + " is after current date."); }//from w ww.j a va 2 s.c om }
From source file:Main.java
public static void main(String[] args) { Calendar futureCal = Calendar.getInstance(); futureCal.set(Calendar.YEAR, 3000); Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); System.out.println("Is futureCal after now ? : " + futureCal.after(now)); }
From source file:Main.java
public static void main(String[] args) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); Calendar cal = Calendar.getInstance(); String today = dateFormat.format(cal.getTime()); System.out.println(today);/*from w ww. java 2 s. c om*/ SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy"); Date actualdate = sdf.parse(today); Date date1 = sdf.parse("20042014"); Date date2 = sdf.parse("23042015"); Calendar actual = Calendar.getInstance(); Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); actual.setTime(actualdate); cal1.setTime(date1); cal2.setTime(date2); System.out.println(actual); System.out.println(cal1); System.out.println(cal2); if (actualdate.after(date1) && actualdate.before(date2)) { System.out.println("Yes"); } else { System.out.println("No"); } if (actual.after(cal1) && actual.before(cal2)) { System.out.println("Yes"); } else { System.out.println("No"); } }
From source file:Main.java
public static boolean isFutureDate(Calendar calToCheck) { return calToCheck.after(GregorianCalendar.getInstance()); }
From source file:Main.java
public static boolean dataEhMaiorOuIgual(Calendar dataFinal, Calendar dataInicial) { return dataFinal.after(dataInicial) || dataFinal.compareTo(dataInicial) == 0; }
From source file:Main.java
private static int elapsed(Calendar before, Calendar after, int field) { Calendar clone = (Calendar) before.clone(); int elapsed = -1; while (!clone.after(after)) { clone.add(field, 1);/*from w w w . ja va2 s .c o m*/ elapsed++; } return elapsed; }
From source file:MainClass.java
public static int countDiffDay(Calendar c1, Calendar c2) { int returnInt = 0; while (!c1.after(c2)) { c1.add(Calendar.DAY_OF_MONTH, 1); returnInt++;/* w ww .j a va 2 s. c om*/ } if (returnInt > 0) { returnInt = returnInt - 1; } return (returnInt); }
From source file:Main.java
public static int intervalDayBetweenDate(Calendar cl1, Calendar cl2) { long interval = 0; if (cl1.after(cl2)) { interval = cl1.getTimeInMillis() - cl2.getTimeInMillis(); } else {//ww w. j a v a2s. c om interval = cl2.getTimeInMillis() - cl1.getTimeInMillis(); } return (int) (interval / MS_OF_ONE_DAY); }