第一种:
t := time.Now() fmt.Println(int(t.Weekday()))
第二种:
yearInt:=time.Now().Year() monthInt:=time.Now().Month()//time.Now().Month().String() dayInt:=time.Now().Day()
fmt.Printf("%d年%d月%d日是:%s\n", yearInt, int(month), dayInt, ZellerFunction2Week(yearInt, int(month), dayInt))
//获取当天是周几 func ZellerFunction2Week(year, month, day int) int { var weekday = [7]int{7, 1, 2, 3, 4, 5, 6} var y, m , c int fmt.Println("ppppppppppp") fmt.Println(reflect.TypeOf(month)) if month >= 3 { m = month y = year % 100 c = year / 100 } else { m = month + 12 y = (year - 1) % 100 c = (year - 1) / 100 } week := y + (y / 4) + (c / 4) - 2*c + ((26 * (m + 1)) / 10) + day - 1 if week < 0 { week = 7 - (-week)%7 } else { week = week % 7 } which_week := int(week) return weekday[which_week] }