• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

Detect Leap Year

How do I detect if its a leap year in Java and change the number of days in a month accordingly ?
0
abuyusuf35
Asked:
abuyusuf35
  • 3
1 Solution
 
CEHJCommented:
Calendar:
Calendar c = Calendar.getInstance();
boolean leap = c.isLeapYear();

Open in new window

0
 
CEHJCommented:
Oops
GrgorianCalendar c = new GregorianCalendar();
boolean leap = c.isLeapYear();

Open in new window

0
 
for_yanCommented:

This deermines niumber of days in a month:
http://www.exampledepot.com/egs/java.util/GetDaysInMonth.html


// Create a calendar object of the desired month
Calendar cal = new GregorianCalendar(1999, Calendar.FEBRUARY, 1);

// Get the number of days in that month
int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28

// Try month in a leap year
cal = new GregorianCalendar(2000, Calendar.FEBRUARY, 1);
days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);     // 29

Open in new window

http://www.dreamincode.net/forums/topic/67757-calculate-the-number-of-days-in-a-month/
0
 
zzynxSoftware engineerCommented:
>> ... and change the number of days in a month accordingly?
What exactly do you mean by that?
0
 
CEHJCommented:
abuyusuf35, can you tell me why you ignored my first comment?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now