第一种:
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 = monthy = year % 100c = year / 100} else {m = month + 12y = (year - 1) % 100c = (year - 1) / 100}week := y + (y / 4) + (c / 4) - 2*c + ((26 * (m + 1)) / 10) + day - 1if week < 0 {week = 7 - (-week)%7} else {week = week % 7} which_week := int(week) return weekday[which_week]}
【golang 获取当天是周几(两种方法)】
推荐阅读
- 【golang】leetcode中级-字母异位词分组&无重复字符的最长子串
- 彻底理解Golang Map
- kratos线上开源年会它来啦~
- 深入浅出 Golang 资源嵌入方案(go-bindata篇)
- 深入浅出 Golang 资源嵌入方案(前篇)
- golang 经典案例总结
- Go实战 | 基于有向无环图的并发执行流的实现
- Golang 数组和切片
- Go JSON编码与解码()
- golang map基础知识