File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes convert XMLGregorianCalender into java.util.date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "convert XMLGregorianCalender into java.util.date" Watch "convert XMLGregorianCalender into java.util.date" New topic
Author

convert XMLGregorianCalender into java.util.date

bhargavi kakarala
Ranch Hand

Joined: Jan 03, 2002
Posts: 82
Hi all,

could anyone of you help me converting XMLGregorianCalendar timestamp into util DateTime and date into Date

here is the sample I have
public XMLGregorianCalendar getEntryDateTime() {
return entryDateTime;
}


Thanks in advance.


Bhargavi
SCJP2,SCWD,SCBCD,IBM Certified SOA Associate,IBM Certified Architectural Design of SOA Solutions
bhargavi kakarala
Ranch Hand

Joined: Jan 03, 2002
Posts: 82
its ok.

I figured it out.


thanks.
pep pepe
Greenhorn

Joined: Jul 16, 2008
Posts: 1
Here is my code::

<blockquote>code:
<pre name="code" class="core">
XMLGregorianCalendar xmlCal = null;
try {
xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
} catch (DatatypeConfigurationException e) {
e.printStackTrace();

}
Calendar now = Calendar.getInstance();
xmlCal.setDay(now.get(Calendar.DAY_OF_MONTH));
// We do a +1 below because XMLGregorianCalendar goes from 1 to 12
// while Calendar.MONTH goes from 0 to 11 !!!
xmlCal.setMonth(now.get(Calendar.MONTH)+1);
xmlCal.setYear(now.get(Calendar.YEAR));
xmlCal.setTime(now.get(Calendar.HOUR_OF_DAY),
now.get(Calendar.MINUTE),
now.get(Calendar.SECOND));
GregorianCalendar c = xmlCal.toGregorianCalendar();
Date fecha = c.getTime();
java.sql.Date fechaSQL = new java.sql.Date(fecha.getTime());
</pre>
</blockquote>
Sergio Rossini
Greenhorn

Joined: May 20, 2009
Posts: 6
More easy (found on this link):

Date convertedDate = xmlGregorianCalendar.toGregorianCalendar().getTime();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert XMLGregorianCalender into java.util.date