code: public static XMLGregorianCalendar convertDate(Date date) {
          if (date == null) {
              return null;
          }
  
          GregorianCalendar gc = new GregorianCalendar();
          gc.setTimeInMillis(date.getTime());
  
          try {
              return getDatatypeFactory().newXMLGregorianCalendar(gc);
          } catch (DatatypeConfigurationException ex) {
              return null;
          }
      }
docs: convert Date to XMLGregorianCalendar.
  
  @param date the date
  @return the xML gregorian calendar