获取当前日期是周几

// 获取当前日期是周几 data是string格式的 “20060102000000”
func ZellerFunction2Week(data string) int {
year :=month(data,0,4)
mon :=month(data,3,6)
day :=month(data,6,8)
var weekday = [7]int{7, 1, 2, 3, 4, 5, 6}
var y, m , c int
if mon >= 3 {
m = mon
y = year % 100
c = year / 100
} else {
m = mon + 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]

}

猜你喜欢

转载自blog.csdn.net/w15562397578/article/details/104970687