首页 > 代码库 > webservice时间类型XMLGregorianCalendar和Date的转换

webservice时间类型XMLGregorianCalendar和Date的转换

//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的转换