Check for Leap Year | JavaScriptSource

Check for Leap Year

JavaScriptSource Staff Apr 21, 2008

General

This snippet will check whether a date belongs to a leap year. Easy to add to an existing script.


Notes

To check whether 1981 is a leap year (it is not)

  // Create a new date
  var d = new Date();

  // Set the year
  d.setFullYear(1981);

  // Output is false
  d.isLeapYear();

Source Code

Paste this source code into the designated areas.

Head

Paste this code into the HEAD section of your HTML document.


Leave a Response

(0 comments)