Hello,
I have following XML generated by serializing a boost::posix_time::ptime structure. I want to create a Java Date object with this XML.
<timeStamp class_id="0" tracking_level="0" version="0">
<ptime_date class_id="1" tracking_level="0" version="0">
<date>20100119</date>
</ptime_date>
<ptime_time_duration class_id="2" tracking_level="0" version="0">
<time_duration_hours>11</time_duration_hours>
<time_duration_minutes>53</time_duration_minutes>
<time_duration_seconds>33</time_duration_seconds>
<time_duration_fractional_seconds>0</time_duration_fractional_seconds>
</ptime_time_duration>
</timeStamp>
Below is the Java code that is supposed to construct Date object by de-serializing this XML. Problem that I am facing is how to break the <date> tag into year/month/day sequence.
Integer date = timeStamp.getPtimeDate().getDate();
Integer hrs = timeStamp.getPtimeTimeDuration().getTimeDurationHours();
Integer mins = timeStamp.getPtimeTimeDuration().getTimeDurationMinutes();
Integer secs = timeStamp.getPtimeTimeDuration().getTimeDurationSeconds();
Calendar cal = Calendar.getInstance();
//TODO
//cal.set(year, month, day, hrs, mins, secs);
Date date = cal.getTime();
Any hints?
EDIT:
I am looking for some elegant solution that doesn't require converting date to a string and then splitting it. That would be my last resort.
Thanks