Solved

Why is it that Java calendar only has 28 days for January 2004?

Posted on 2003-11-02
8
292 Views
Last Modified: 2010-03-31
I tried using Java Calendar and I realized that January 2004 has only 28 days.
I added 2 days to the date 28 January 2004 , but the returned date is 2 Feb 2004...
Y is it so?

0
Comment
Question by:agamarjo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9668238
post your code
0
 
LVL 2

Expert Comment

by:smitty22
ID: 9668311
Remember, it's zero-based:

0 = january
1 = february
2 = may
0
 
LVL 2

Expert Comment

by:smitty22
ID: 9668316
2 = march, that is
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 9672058
The following code snippet

      java.text.SimpleDateFormat dayFormatter =
        new java.text.SimpleDateFormat("dd/MM/yyyy");
      java.util.Calendar c = java.util.Calendar.getInstance();
      c.set(2004,0,28);
      c.add(java.util.Calendar.DATE, 2);
      System.out.println(dayFormatter.format(c.getTime()));

nicely prints out:

       30/01/2004

Hope this is helpful to you.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9672434
I still haven't seen a good reason, but smitty22 is right, months are numbered 0 .. 11.

Days and years use the actual values.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 9676770
Hi Agamarjo,
Thanks for the acceptance.

For helping me answering future questions better, can you tell me what I could have done better to deserve an A grade?

Kind regards.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9677322
That's a grade 'A' answer.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 9708211
Hi jimmack,
Thanks for sharing your opinion (and thus strengthen mine)
The fact that the author of the question keeps quiet proves s/he thinks the same way about it.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question