my dog learned polymorphism
The moose likes Java in General and the fly likes getting current month and year Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "getting current month and year" Watch "getting current month and year" New topic

getting current month and year

Sanny kumar
Ranch Hand

Joined: May 18, 2005
Posts: 53
Hi all,

I m writing a java program.i want to display the current mont ex:sep and current year:2005 .can anyone please help?

i m using java.util but i m facing problem..can anyone please write the code?

Thanks in advance
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Use this

Calendar cal = new GregorianCalendar();

// Get the components of the date
int era = cal.get(Calendar.ERA); // 0=BC, 1=AD
int year = cal.get(Calendar.YEAR); // 2002
int month = cal.get(Calendar.MONTH); // 0=Jan, 1=Feb, ...
int day = cal.get(Calendar.DAY_OF_MONTH); // 1...
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday,2=Monday, ...

Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
I agree. Here's the link:
subject: getting current month and year
jQuery in Action, 3rd edition