Solved

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

Posted on 2003-11-02
8
288 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
  • 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nextBoolean(double p) for Random class 3 40
xampp tool 12 51
fibonacci ten numbers 4 39
ejb on wildfly 5 20
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

810 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