fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.SimpleDateFormat;
  7. import java.util.Calendar;
  8. import java.util.Date;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. static SimpleDateFormat parserSDF=new SimpleDateFormat("yyyy-MM-DD");
  14.  
  15.  
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. System.out.println(checkIfInRange(parserSDF.parse("2014-12-31")));
  19. }
  20.  
  21.  
  22. public static boolean checkIfInRange(Date date){
  23.  
  24. Calendar cal= Calendar.getInstance();
  25.  
  26. cal.add(Calendar.YEAR, -1);
  27. Date yearBeforeToday = cal.getTime();
  28. cal.add(Calendar.YEAR, 2);
  29. Date yearAfterToday = cal.getTime();
  30.  
  31. return date.after(yearBeforeToday) && date.before(yearAfterToday);
  32. }
  33. }
Success #stdin #stdout 0.13s 321280KB
stdin
Standard input is empty
stdout
false