Two Laptop Bag
The moose likes Beginning Java and the fly likes Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date" Watch "Date" New topic



Joined: May 21, 2001
Posts: 4
How do get the current month
or the current year?
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
try java.util.GregorianCalendar's get() method (inherited from Calendar). useful constants for the <code>field</code> paramter to get() can be found in Calendar and GrgorianClandar too.
another thing would be to use System.getCurrentTimeMillis (dont know if this is the good name) and calculate it yourself :-)


Joined: May 21, 2001
Posts: 4
I used...
Calendar userCalendar = new GregorianCalendar();
userMonth = userCalendar.get(Calendar.MONTH);
and userMonth was = 4
Isn't May=5?
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
public static final int MONTH is zero based. January = 0, Febuary = 1 e.t.c
You must bare this in mind when using this field data.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Date
jQuery in Action, 3rd edition