• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting current month and year

 
Sanny kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 824
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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, ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic