Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有什么捷径可以将 java.time.ZonedDateTime 转换为 XMLGregorianCalendar?
也许我需要一些中间步骤,比如将 ZonedDateTime 转换为 java.util.Date,但这会使代码过于混乱。
该问题出现在 JAX-WS Web 服务中,日期时间作为 XMLGregorianCalendar 传递。
目前我认为这是最直接的方法:
ZonedDateTime now = ZonedDateTime.now(); GregorianCalendar gregorianCalendar = GregorianCalendar.from(now); XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);