3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[メモ] Go言語でうるう年を判定する

Posted at

へえと思ったのでメモ。
以下の記事を参考にした。

Golang : How to determine if a year is leap year?

うるう年を判定するロジックを愚直に実装している記事は見かけるが、 Time.YearDay を使えば年間の日数が返ってくるため、うるう年かどうかが判定可能という事だった。
こちらの方が標準パッケージのロジックを再利用できてよさそう。

year := time.Date(y, time.December, 31, 0, 0, 0, 0, time.Local)
days := year.YearDay()

if days > 365 {
        return true
} else {
        return false
}
3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?