第2土曜日とか、第3金曜日とか、第*曜日を知りたいときあると思います。
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
count := getCountWeekday(now)
fmt.Printf("第%d%s\n",count,now.Weekday())
// 第2火曜日かどうか
fmt.Println(count == 2 && now.Weekday() == time.Tuesday)
}
func getCountWeekday(now time.Time) int {
count := 0
for t := now; t.Month() == now.Month(); t = t.Add(-7 * 24 * time.Hour) {
count++
}
return count
}
実行結果
第2Tuesday
true