File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: getting current month and year
 
Similar Threads
Mock Exam Links needed (and Happy New Year)
Convert AWK script
Java OCR API
wants to do Oracle Certification
Displaying tree using Richfaces