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 8985757
In Process

The Archive Base Latest Questions

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

I need to parse a custom defined date format, defined in a device that

  • 0

I need to parse a custom defined date format, defined in a device that I need to communicate where the date is given as the number of seconds counted from the year 2000.

I tried to use GregorianCalendar to parse this data, this is the code I tried:

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setGregorianChange(new Date(2000 - 1900, 0, 1));

The Date object corresponds to January 1st 2000. And I thought that with this I was fine to setTimeInMillis to get the correct date multiplying the time I read by 1000, as it’s counted in seconds not in miliseconds as GregorianCalendar, but it didn’t work. I tried setTimeInMillis(0), waiting that the time corresponding to calendar corresponds to January 1st 2000 but it doesn’t, it corresponds to December 18th 1969.

How can I configure GregorianCalendar so I can setTimeInMillis(0) and it corresponds to January 1st 2000? If it’s not possible, is there any other class I can use instead of creating all the code by myself?

Thanks in advance.

  • 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-15T21:23:45+00:00Added an answer on June 15, 2026 at 9:23 pm

    setGregorianChange only changes the point in time where the switch from Julian to Gregorian happened. It defaults to the correct historical value.

    But since pretty much everyone else out there is using proleptic Gregorian, there is a valid use case for this function:

    setGregorianChange(new Date(Long.MIN_VALUE)) //Julian never happened
    

    This is also what JodaTime uses by default.

    Anyway, you can just subtract 946684800000L from the normal millisecond unix timestamp, and divide by 1000:

    public static long secondsSince2000(Date input) {
        final long epoch = 946684800000L;
        return (input.getTime() - epoch) / 1000L;
    }
    

    To convert from seconds since 2000:

    public static Calendar fromSecondsSince2000( long seconds ) {
        final long epoch = 946684800000L;
        Calendar cal = GregorianCalendar.getInstance();
        long timestamp = epoch + seconds * 1000L;
        cal.setTime(new Date(timestamp));
        return cal;
    }
    

    To see that both are working:

        long sec = secondsSince2000(new Date());
        Calendar cal = fromSecondsSince2000( sec );
        System.out.println(cal.getTime().toString().equals(new Date().toString()));
    

    They should print true

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

Sidebar

Related Questions

I need a solution that can parse a date string but replaced with a
I'm want to parse a custom string format that is persisting an object graphs
Need to parse a file for lines of data that start with this pattern
i need to parse simple JSON php in my tableview for that i searched
I need to parse/extract information from an html page. Basically what I'm doing is
I need to parse the payload from different push notification, but if user press
I have a custom QWidget subclass that lays out a number of children. In
The custom date strings in .NET allow you to parse a date with seven
I am getting some response from server side which i need to parse but
We have received a WSDL from our client that we use to communicate with

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.