Friday, April 3, 2015

How to convert java.uitl.Date to XMLGregorianCalendar

P
The following code sample will show you how to convert Date object to XMLGregorianCalendar object. XMLGregorianCalendar is often meet when you write a client service application that invoke server's API with Date as parameter.

DateFormat df = new SimpleDateFormat("MMM dd, yyyy h:mm a");
Date effect_to = df.parse("Jun 20, 2015 9:30 AM");
GregorianCalendar c = new GregorianCalendar();
c.setTime(effect_to);
XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

Done! Hope this will help you.

No comments:

Post a Comment