Skip to content

Instantly share code, notes, and snippets.

@jgcasta
Last active December 16, 2015 21:39
Show Gist options
  • Save jgcasta/5501423 to your computer and use it in GitHub Desktop.
Save jgcasta/5501423 to your computer and use it in GitHub Desktop.
Return a XMLGregorianCalendar from a Date object in java
public static XMLGregorianCalendar date2XMLGregorianCalendar(Date fecha, Date hora) {
Calendar calendarFecha = Calendar.getInstance();
calendarFecha.setTime(fecha);
Calendar calendarHora = Calendar.getInstance();
calendarHora.setTime(hora);
//System.out.println("hora->" + calendarHora.get(Calendar.HOUR_OF_DAY) + "/" + calendarHora.get(Calendar.MINUTE) + "/" +calendarHora.get(Calendar.SECOND));
GregorianCalendar fechaX = new GregorianCalendar(calendarFecha.get(Calendar.YEAR),
calendarFecha.get(Calendar.MONTH),
calendarFecha.get(Calendar.DAY_OF_MONTH),
calendarHora.get(Calendar.HOUR_OF_DAY),
calendarHora.get(Calendar.MINUTE),
calendarHora.get(Calendar.SECOND) );
XMLGregorianCalendar fechaXML = null;
try {
fechaXML = DatatypeFactory.newInstance().newXMLGregorianCalendar(fechaX);
} catch (DatatypeConfigurationException e) {}
return fechaXML;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment