Note that there are some explanatory texts on larger screens.

plurals
  1. POA bug in Java XMLGregorianCalendar conversion to a Java util.Date?
    text
    copied!<p>I'm writing a date/time value to an XML file by reading the date from a RAP based UI as a Java Date object, and passing it as an <code>XMLGregorianCalendar</code> object to actual file writing code. The corresponding classes are auto generated and I don't have control over them. The date I entered was:</p> <blockquote> <p>03-03-1933:03:03:03.</p> </blockquote> <p>It got converted to the following string when written in the file:</p> <blockquote> <p>1933-03-03T03:03:03.161+05:53</p> </blockquote> <p>Now, when I read the date back to show it in the UI for edit, it appeared there as:</p> <blockquote> <p>03-03-1933:03:03:23</p> </blockquote> <p>Note the extra 20 seconds added to the actual seconds value.</p> <p>Why is this happening? Is it some bug in the API? Any help will be much appreciated!</p> <p>Relevant code:</p> <p>1) Converting to <code>XMLGregorianCalendar</code>from <code>Date</code>:</p> <pre><code>GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(date.getTime()); XMLGregorianCalendar date2; date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); // pass 'date2' to file writing code </code></pre> <p>2) Converting to <code>Date</code> from <code>XMLGregorianCalendar</code>:</p> <pre><code>XMLGregorianCalendar cal = getDateFromFile(); // XML date read from file Date date = cal.toGregorianCalendar().getTime(); // show Date object in UI, dateCtrl and timeCtrl are SWT DateTime objects GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime( date ); dateCtrl.setDate( calendar.get( GregorianCalendar.YEAR ), calendar.get( GregorianCalendar.MONTH ), calendar.get( GregorianCalendar.DAY_OF_MONTH ) ); timeCtrl.setTime( calendar.get( GregorianCalendar.HOUR_OF_DAY ), calendar.get( GregorianCalendar.MINUTE ), calendar.get( GregorianCalendar.SECOND) ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload