What is the best way to convert XMLGregorianCalendar to MM/dd/yyyy hh:mm String?

前端 未结 5 719
无人共我
无人共我 2021-02-04 00:18

What is the best way to convert XMLGregorianCalendar objects to \'MM/dd/yyyy hh:mm\' String?

5条回答
  •  温柔的废话
    2021-02-04 00:42

    This example convert XMLGregorianCalendar to date

    XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
    Date date = xmlCalendar.toGregorianCalendar().getTime();
    

    This example convert date to string

    DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm");
    String dateStr = df.format(GregorianCalendar.getInstance().getTime());
    

提交回复
热议问题