Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:17:44+00:00 2026-06-12T21:17:44+00:00

I am trying to convert from millisecond time stamp to XMLGregorianCalendar and back, but

  • 0

I am trying to convert from millisecond time stamp to XMLGregorianCalendar and back, but I seem to be getting wrong results. Am I doing something wrong? It seems I am gaining days.

    // 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?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:17:45+00:00Added an answer on June 12, 2026 at 9:17 pm

    Interesting – it works fine for values down to (about) -10000000000000L (and positive values) but larger negative values become inconsistent.

    If you print out gc, xc, and gc2, you can see where the problem arises (the conversion from XMLGregorianCalendar to GregorianCalendar

    gc:  java.util.GregorianCalendar[time=-62135740800000 ... DAY_OF_WEEK=7
    xc:  0001-01-01T08:00:00.000Z
    gc2: java.util.GregorianCalendar[time=? ... DAY_OF_WEEK=5
    

    If you print out the fields of xc, you get 1,1,1.

        System.out.println(xc.getYear());
        System.out.println(xc.getMonth());
        System.out.println(xc.getDay());
    

    For gc2, you get 1,0,1 (which matches xc, because months are zero-based in GregorianCalendar)

        System.out.println(gc2.get(gc2.YEAR));
        System.out.println(gc2.get(gc2.MONTH));
        System.out.println(gc2.get(gc2.DAY_OF_MONTH));
    

    However, adding these 3 println calls changes the output from printing out gc2! – the time=? output from gc2 changes to time=-62135568000000 – so some calculation has been triggered by querying the GregorianCalendar object; the areFieldsSet property also changes from false to true.

    The timezones of the two GregorianCalendars are different, but this does not account for the error, which persists even if you set explicit TimeZone and Locale.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert an animation from cocos2d to cocos2d-x but to no avail.
I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in
This is probably easy, but I'm trying to convert from a source which provides
I'm trying to convert something from my excel spreadsheets into Javascript and came along
I am trying to convert from an int to a string but I am
Am trying to convert my string value(the value is millisecond value) from seconds. Here
I am trying to convert from string to DataTime but an an error occurs.
trying to convert from java to objective-c. im havin a hard time finding anything
I'm having the hardest time trying to convert this date from an API to
There is some code that I'm trying to convert from IList to IEnumerable :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.