Próbuję przekonwertować z milisekundowej sygnatury czasowej na XMLGregorianCalendar iz powrotem, ale wydaje się, że otrzymuję złe wyniki. czy robię coś źle? Wygląda na to, że zyskuję kilka dni.Long To XMLGregorianCalendar i wróć do Long
// Time stamp 01-Jan-0001 00:00:00.000
Long ts = -62135740800000L;
System.out.println(ts);
System.out.println(new Date(ts)); // Sat Jan 01 00:00:00 PST 1 .. Cool!
// to Gregorian Calendar
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(ts);
// to XML Gregorian Calendar
XMLGregorianCalendar xc = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
// back to GC
GregorianCalendar gc2 = xc.toGregorianCalendar();
// to Timestamp
Long newTs = gc2.getTimeInMillis();
System.out.println(newTs); // -62135568000000 .. uh?
System.out.println(new Date(newTs)); // Mon Jan 03 00:00:00 PST 1 .. where did the extra days come from?
Jeśli dodaję 'gc2.get (GregorianCalendar.YEAR);' wtedy dzień jest poprawny, ale teraz ROK jest wyłączony przez 1969 rok. –
To dziwne - nie widzę tego! Dzień się nie udaje, a rok jest jeszcze 1. Zastanawiam się, czy to zależy od wersji Java (używam 1.6.0_27) czy Locale (jestem 'en_GB') .. ??? – DNA