当前位置: 代码迷 >> Web前端 >> webservice时间Date处置
  详细解决方案

webservice时间Date处置

热度:466   发布时间:2012-11-06 14:07:00.0
webservice时间Date处理

在webservice中java.util.Date作为参数传递时需要转化为XMLGregorianCalendar类型

?

?

public XMLGregorianCalendar convertToXMLGregorianCalendar(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;
    }

?

?

     public  Date convertToDate(XMLGregorianCalendar cal) throws Exception{
         GregorianCalendar ca = cal.toGregorianCalendar();
         return ca.getTime();
     }

?

  相关解决方案