XMLGregorianCalendar与Date互转

// javax.xml.datatype.XMLGregorianCalendar
// java.util.GregorianCalendar
// javax.xml.datatype.DatatypeFactory
// java.time.ZoneId

// Date 转 XMLGregorianCalendar 
Date date = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
XMLGregorianCalendar webserviceDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);


// XMLGregorianCalendar 转 Date
cal = webserviceDate.toGregorianCalendar();
date = ca.getTime();

// XMLGregorianCalendar 转 LocalDate
LocalDate localDate = webserviceDate.toGregorianCalendar().toZonedDateTime().toLocalDate();

// LocalDate 转 XMLGregorianCalendar
cal  = GregorianCalendar.from(localDate.atStartOfDay(ZoneId.systemDefault()));
webserviceDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);

你可能感兴趣的:(XMLGregorian,Calendar,Gregorian,Date)