Forums Register Login

calendar error

+Pie Number of slices to send: Send


i expected on output of

3, since it's March.

but somehow i'm getting a 2.

i have no clue how to fix this and what i'm doing wrong.
+Pie Number of slices to send: Send
Unfortunately, months are zero-based in class Calendar. So, 0 = January, 1 = February, 2 = March, etc., until 11 = December. That's just how class Calendar was designed.

Note: You do not need to declare that your class might throw ClassNotFoundException. Remove line 10.
+Pie Number of slices to send: Send
i see, thanks!


and i cleaned my code. thanks for the tip
+Pie Number of slices to send: Send
You should learn to read the java API. This has all the documentation for the predefined classes, including the Calendar class. It states in there:

MONTH
public static final int MONTH
Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.

(emphasis added by me)

Usually, when I'm coding, I always have that page open to check and see what things do.
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 457 times.
Similar Threads
Is it possible to generate a random date with gregorian calendar?
Switch with Boolean ???
how to add 30 days to current data?
Date -problem
Gregorian Calendar always returns same values
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:43:11.