Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/datetime/mod.ts>isLeap

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function isLeap
import { isLeap } from "https://deno.land/std@0.195.0/datetime/mod.ts";

Returns whether the given date or year (in number) is a leap year or not in the local time zone. based on: https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year

Examples

Example 1

import { isLeap } from "https://deno.land/std@0.195.0/datetime/is_leap.ts";

isLeap(new Date("1970-01-02")); // => returns false
isLeap(new Date("1972-01-02")); // => returns true
isLeap(new Date("2000-01-02")); // => returns true
isLeap(new Date("2100-01-02")); // => returns false
isLeap(1972); // => returns true

Some dates may return different values depending on your timezone.

Example 2

import { isLeap } from "https://deno.land/std@0.195.0/datetime/is_leap.ts";

isLeap(new Date("2000-01-01")); // => returns true if the local timezone is GMT+0, returns false if the local timezone is GMT-1
isLeap(2000); // => returns true regardless of the local timezone

Parameters

year: Date | number

year in number or Date format

Returns

boolean