You are putting there a two-digits year. The first century. And the Gregorian calendar started in the 16th century. I think you should add 2000 to the year.
Month in the function new GregorianCalendar(year, month, days)
is 0-based. Subtract 1 from the month there.
Change the body of the second function as follows:
String dateFormatted = null;
SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM-yyyy");
try {
dateFormatted = fmt.format(date);
}
catch ( IllegalArgumentException e){
System.out.println(e.getMessage());
}
return dateFormatted;
After debugging, you'll see that simply GregorianCalendar
can't be an argument of the fmt.format();
.
Really, nobody needs GregorianCalendar
as output, even you are told to return "a string".
Change the header of your format function to
public static String format(final Date date)
and make the appropriate changes. fmt.format()
will take the Date
object gladly.