Java Calender and Date object is always confusing for a beginner and one of the typical situation is to create a Date object with no time information from a Calender or another Date object. One of the typical usage is when we need to compare Date with one stored in a database in say 'dd-MMM-yy' format.
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, offset);
SimpleDateFormat dayMonthYear = new SimpleDateFormat("dd-MMM-yy");
String newDate=dayMonthYear.format(calendar.getTime());
Date fmtDate=null;
try {
fmtDate = dayMonthYear.parse(newDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Time in getDate" + fmtDate);
Comments
Post a Comment