简体   繁体   中英

How to convert java.time.ZonedDateTime to XMLGregorianCalendar?

Is there any short way to convert java.time.ZonedDateTime to XMLGregorianCalendar?

Maybe I need some intermediate steps like convert ZonedDateTime to java.util.Date, but that will make code too messy.

The problem appeared in JAX-WS web services, datetime there is passed as XMLGregorianCalendar.

At the current moment I think it's the most straightforward way to do it:

ZonedDateTime now = ZonedDateTime.now();
GregorianCalendar gregorianCalendar = GregorianCalendar.from(now); 
XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM