Last active
October 21, 2021 07:05
-
-
Save KanDai/722d89eec7378da43ee0930c2665ef59 to your computer and use it in GitHub Desktop.
閏年かどうかを判定する関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 閏年かどうかを判定する関数 | |
* 引数がない場合の今の年で判定する | |
* 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