How can I utilize SimpleDateFormat with Calendar?
Try this:
Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
dateFormat.setTimeZone(cal.getTimeZone());
System.out.println(dateFormat.format(cal.getTime()));
eQui's answer is missing a step
Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
#---- This uses the provided calendar for the output -----
dateFormat.setCalendar(cal);
System.out.println(dateFormat.format(cal.getTime()));
Calendar.getTime() returns a Date which can be used with SimpleDateFormat.
Simply call calendar.getTime()
and pass the resulting Date
object to the format
method.