Solved

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

Posted on 2003-11-02
8
290 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 11 56
What's wrong with this code? 4 34
CSV file parsing thru Java 13 39
Finding all private fields and their corresponding getters setters for nested classes 4 21
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

740 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