常见标准的写法"yyyy-MM-dd HH:mm:ss",区分大小写,时间是24小时制,24小时制转换成12小时制只需将HH改成hh。

String to Date:

String sdate = "2016-3-14";
SimpleDateFormate sdf = new SimpleDateFormate("yyyy-MM-dd");
Date date = sdf.parse(sdate);

Date to String:

sdate = (new SimpleDateFormate("yyyy-MM-dd")).formate(date);

Date to XMLGregorianCalendar:

        GregorianCalendar cal = new GregorianCalendar();  
        cal.setTime(date);  
        XMLGregorianCalendar gc = null;  
        try {  
            gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);  
        } catch (Exception e) {  
  
             e.printStackTrace();  
        } 
     return gc;

 

相关文章:

  • 2022-12-23
  • 2021-11-05
  • 2021-07-29
  • 2022-12-23
  • 2022-02-08
  • 2022-02-08
  • 2021-08-12
猜你喜欢
  • 2021-10-31
  • 2021-07-11
  • 2021-11-05
  • 2021-12-09
  • 2022-01-11
  • 2021-10-02
  • 2021-11-23
相关资源
相似解决方案