I want to add 5 days delay to XMLGregorianCalendar date (date is coming from json request). I tried converting it first to LocalDateTime as follows, this works
LocalDateTime date = request.getDate().toGregorianCalendar().toZonedDateTime().toLocalDateTime().plusDays(5);
Timestamp ts = Timestamp.valueOf(date);
Another approach I tried was as follows, which is throwing below error
Timestamp date = DateUtil.convertToTimestamp(request.getDate().
add(DatatypeFactory.newInstance().newDuration("P14D"));
Error:
Required type: XMLGregorianCalendar
Provided: void
Although, the LocalDateTime one does not give any errors, I am just wondering if there's an easy way to do this. Any help would be appreciated. Thanks in advance!
Don’t use the Timestamp class. It doesn’t do what you think it does. In fact, it doesn’t even do what it was originally intended to do all that well (represent a particular SQL type).
Just use the add method of GregorianCalendar: