Leetcode Note: Go - Day of the Year

Day of the Year - LeetCode
https://leetcode.com/problems/day-of-the-year/

  • Go 言語で取り組んだメモ

回答

Go Solution using Standard Library - 0ms - LeetCode Discuss
https://leetcode.com/problems/day-of-the-year/discuss/832891/Go-Solution-using-Standard-Library-0ms

func dayOfYear(date string) int {
	t, _ := time.Parse("2006-01-02", date)
	start := time.Date(t.Year(), 1, 1, 0, 0, 0, 0, time.UTC)

	return int(t.Sub(start).Round(time.Hour).Hours())/24 + 1
}