Last active
December 16, 2015 21:39
-
-
Save jgcasta/5501423 to your computer and use it in GitHub Desktop.
Return a XMLGregorianCalendar from a Date object in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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