Skip to content

Instantly share code, notes, and snippets.

@KanDai
Last active October 21, 2021 07:05
Show Gist options
  • Save KanDai/722d89eec7378da43ee0930c2665ef59 to your computer and use it in GitHub Desktop.
Save KanDai/722d89eec7378da43ee0930c2665ef59 to your computer and use it in GitHub Desktop.
閏年かどうかを判定する関数
/**
* 閏年かどうかを判定する関数
* 引数がない場合の今の年で判定する
* Date()の第3引数に0を指定すると最後の日が取得できるのを利用して2月最終日を取得して判定する
*/
const isLeapYear = (year: number): boolean => {
const y = year ? year : new Date().getFullYear()
return new Date(y, 2, 0).getDate() === 29
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment