Solved

Detect Leap Year

Posted on 2011-10-10
Medium Priority
235 Views
How do I detect if its a leap year in Java and change the number of days in a month accordingly ?
0
• 3

LVL 86

Expert Comment

ID: 36942923
Calendar:
``````Calendar c = Calendar.getInstance();
boolean leap = c.isLeapYear();
``````
0

LVL 86

Expert Comment

ID: 36942937
Oops
``````GrgorianCalendar c = new GregorianCalendar();
boolean leap = c.isLeapYear();
``````
0

LVL 47

Accepted Solution

for_yan earned 2000 total points
ID: 36942983

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
``````
http://www.dreamincode.net/forums/topic/67757-calculate-the-number-of-days-in-a-month/
0

LVL 37

Expert Comment

ID: 36947685
>> ... and change the number of days in a month accordingly?
What exactly do you mean by that?
0

LVL 86

Expert Comment

ID: 37029933
abuyusuf35, can you tell me why you ignored my first comment?
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.