skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Sunday, October 28, 2012

Getting dates without time portion

Posted by Raju Gupta at 11:00 AM – 0 comments
 

This code snippet helps to retrieve a particular date without its time portion.

public static Date getDate(Date inDate){
  if(inDate != null){
                       Calendar objCalendar = new GregorianCalendar();
   objCalendar.setTime(inDate);
   objCalendar.set(Calendar.HOUR_OF_DAY, 0);
   objCalendar.set(Calendar.MINUTE, 0); 
   objCalendar.set(Calendar.SECOND, 0); 
   objCalendar.set(Calendar.MILLISECOND, 0); 
   return (objCalendar.getTime());
  }else{
   return null;
  }
 }



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