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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:44:49+00:00 2026-05-24T13:44:49+00:00

I am building a CalendarDisplay application for Android. Among other things, this application allows

  • 0

I am building a CalendarDisplay application for Android. Among other things, this application allows the user to select the number of days to add to an epoch (epoch is a date in 1899), and that result will be represented graphically on the display. However, when I set Date value from a Calendar value, I get unexpected results: the year seems to be off by a value of 1900. While I could simply add 1900 to the result, that seems like the wrong answer since what I am doing is (I believe) by the book. Or I could continue with what I have; that works too. But that shares the same by-the-book issue. Here is the code, with spare variables for debugging:

public void gotoCal(int days) {
    // epochCal has been initialized as follows:
    // (HYF_BASE_YEAR = 1899,  HYF_BASE_MONTH = 11, HYF_BASE_DAY = 1)
    // epochCal = (Calendar) Calendar.getInstance();
    // epochCal.set(HYF_BASE_YEAR, HYF_BASE_MONTH, HYF_BASE_DAY);

    Calendar cal = (Calendar) epochCal.clone();
    cal.add(Calendar.DATE, days);
    int year = cal.get(Calendar.YEAR);
    Date date = cal.getTime();
    int year2 = date.getYear();
    if (year2 != year) {
        date.setYear(year);
    }
    int year3 = date.getYear();
    gotoDate(date);
}

Now, when I run this code in debug mode as gotoCal(40000), with a breakpoint at the gotoDate() line, I see the following values in the fields:
year = 2009 ,
year2 = 109 ,
year3 = 2009

Is the Calendar.getTime() function supposed to return a date that’s 1900 years in the past (I have seen no such documentation)? Or might I be doing something to influence it to do that? Or what else might I be doing wrong?

  • 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-05-24T13:44:51+00:00Added an answer on May 24, 2026 at 1:44 pm

    You’ve misread (or not read) the documentation for Date.getYear:

    Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

    Also:

    • Date.getYear is deprecated, and for good reason. It uses the default time zone, and basically shouldn’t be used.

    • Joda Time is much better date and time API. I’d thoroughly recommend using that instead of Date/Calendar.

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

Sidebar

Related Questions

Building our Android app from Ant fails with this error: [apply] [apply] UNEXPECTED TOP-LEVEL
Building a Jquery application which calls a number of endpoints to access data from
Building an application, before using a real database, just to get things work I
Building a client-side swing application what should be notified on a bus (application-wide message
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
Building a new ASP.net application, and planning to separate DB, 'service' tier and Web/UI
Building an app using android.support.v4.app , targeting API level 8. Everything's working as planned
Building an NSCharacter set to restrict a UITextField for entering user names. I want
Building on this question , is there a simple solution for having a multi-key
Building on this this post , I needed a clean way to extract nodes

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.