0

Hi I have this method

public static Date toDate(XMLGregorianCalendar calendar) 
  if (calendar == null) {
    return null;
  }
  return calendar.toGregorianCalendar().getTime();
}

The date I get from this method is with this format Fri May 30 12:00:00 EEST 2014 but I wan the format to be like dd-MM-yyyy HH:mm:ss any idea how ??

Yara Mousa
  • 79
  • 6
  • 15
  • http://stackoverflow.com/questions/14060161/specify-the-date-format-in-xmlgregoriancalendar http://stackoverflow.com/questions/16031903/xmlgregoriancalendar-formatting-in-mm-dd-yyyy http://stackoverflow.com/questions/14392811/date-to-xmlgregoriancalendar-with-specific-format http://stackoverflow.com/questions/14688526/what-is-the-best-way-to-convert-xmlgregoriancalendar-to-mm-dd-yyyy-hhmm-string are all very similar and would answer your question. Google really should be your first step. – flaviut Jun 11 '14 at 15:46

1 Answers1

1

Try with SimpleDateFormat to format the date object as per your need.

DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
System.out.println(formatter.format(new Date()));

output:

11-06-2014 21:13:49

You are getting default toString() implementation of Date object.

Find the source code here Date#toString() that uses EEE MMM dd HH:mm:ss zzz yyyy pattern.

Braj
  • 46,415
  • 5
  • 60
  • 76