skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Tuesday, October 16, 2012

Function to Check Given Date is Older Than 900 days

Posted by Raju Gupta at 6:00 PM – 0 comments
 
The code snippet will results in a boolean using which we can identify that given date is older than 900 days or not.

/**
  * @param args
  * @throws ParseException 
  */
 public static void main(String[] args){
  // TODO Auto-generated method stub
  
  boolean result = false;
  SimpleDateFormat simpleDateFormat = new SimpleDateFormat("ddMMyy");
  simpleDateFormat.setLenient(false);
  Date flightDateParsed = null;
  try {
   //Pass the date which we need to check
   flightDateParsed = simpleDateFormat.parse("101111");
  } catch (ParseException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  //create Calendar instance
  Calendar olderDate = Calendar.getInstance();
  olderDate.add(Calendar.DATE, -900);
  olderDate.set(Calendar.HOUR_OF_DAY, 0);
  olderDate.set(Calendar.MINUTE, 0);
  olderDate.set(Calendar.SECOND, 0);
  olderDate.set(Calendar.MILLISECOND, 0);
  if (flightDateParsed.before(olderDate.getTime())){
   result = true;
  }
  System.out.println("True = Given Date is Older Than 900 days:::::"+result);
 }


Labels: Java File Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger