Check for a Leap Year using GregorianCalendar in Java

Description

The following code shows how to check for a Leap Year using GregorianCalendar.

Example


/*  www  .jav a  2  s.  c  o  m*/
import java.text.ParseException;
import java.util.GregorianCalendar;

public class Main {

  public static void main(String[] args) throws ParseException {
    System.out.println(isLeapYear(2000));
  }

  public static boolean isLeapYear(int year) {

    GregorianCalendar gcal = new GregorianCalendar();
    return gcal.isLeapYear(year);
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone