LoginSignup
0
0

More than 3 years have passed since last update.

[Javascript] うるう年かどうかを確認するJS

Posted at

はじめに

うるう年であるかを確認するJS方法は様々です。
ですが、今回Dateを利用して簡単に解けたというのがポイントです。

Dateを利用して簡単

function isLeapYear(year) {
  return new Date(year, 1, 29).getDate() === 29;
}

isLeapYear(2024)
true
isLeapYear(2100)
false
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0