Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert XMLGregorianCalender into java.util.date

 
bhargavi kakarala
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 kakarala
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its ok.

I figured it out.


thanks.
 
pep pepe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More easy (found on this link):

Date convertedDate = xmlGregorianCalendar.toGregorianCalendar().getTime();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic