LocalDateTime to XMLGregorianCalendar 1

LocalDateTime to XMLGregorianCalendar

LocalDateTime localDatetime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");

String formattedDate = localDatetime.format(formatter);
XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(formattedDate);

Here is what the above code is Doing:
1. Create a LocalDateTime object with the current date and time.
2. Create a DateTimeFormatter object with the pattern you want to use.
3. Format the LocalDateTime object using the formatter.
4. Create a new XMLGregorianCalendar object using the formatted date.

Similar Posts