码迷,mamicode.com
首页 > Web开发 > 详细

webservice时间类型XMLGregorianCalendar和Date的转换

时间:2017-03-08 15:34:52      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:gre   nbsp   XML   actor   try   reg   rac   exception   cat   

//ISO日期转换为UTC日期  
public XMLGregorianCalendar xmlToDate(Date date){  
    GregorianCalendar cal = new GregorianCalendar();  
        cal.setTime(date);  
        XMLGregorianCalendar gc = null;  
        try {  
            gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);  
        } catch (Exception e) {  
             e.printStackTrace();  
        }  
    return gc;  
}  
  
//UTC日期转换为ISO日期  
public Date DateToXML(XMLGregorianCalendar gc){  
    GregorianCalendar ca = gc.toGregorianCalendar();  
        return ca.getTime();  
}  

 

webservice时间类型XMLGregorianCalendar和Date的转换

标签:gre   nbsp   XML   actor   try   reg   rac   exception   cat   

原文地址:http://www.cnblogs.com/allanzhang/p/6519655.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!