• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Time & Date / Check if the given year is a leap year

Check if the given year is a leap year

Check if the given year is a leap year

Use new Date(), setting the date to February 29th of the given year. Use Date.prototype.getMonth() to check if the month is equal to 1.

const isLeapYear = year => new Date(year, 1, 29).getMonth() === 1;

// Examples
isLeapYear(2019); // false
isLeapYear(2020); // true

Source

https://www.30secondsofcode.org/js/s/is-leap-year

Time & Date

Related Snippets:

  • Calculate the difference (in hours) between two dates
  • Get the amount of time from now for a date
  • Date of yesterday
  • Alarm Clock

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers