Convert Date to XMLGregorianCalendar in Java
XML Gregorian Calendar: The rules for specifying dates in XML format are defined in the XML Schema standard. The Java XMLGregorianCalendar class, introduced in Java 1.5, is a representation of the W3C XML Schema 1.0 date/time datatypes and is required to use the XML format.
In this approach, we have first changed the standard date to Gregorian Calendar date format and then changed it to XML Gregorian Date using the DatatypeFactory(). newInstance method which creates new javax.xml.datatype Objects that map XML to/from Java Objects.
Standard Format :- Tue Feb 16 17:44:25 UTC 2021 XMLGregorianCalendar Format :- 2021-02-16T17:44:25.164Z