// getYearMonthToDay 查询指定年份指定月份有多少天
// @params year int 指定年份
// @params month int 指定月份
func getYearMonthToDay(year int, month int) int {
// 有31天的月份
day31 := map[int]struct{}{
1: struct{}{},
3: struct{}{},
5: struct{}{},
7: struct{}{},
8: struct{}{},
10: struct{}{},
12: struct{}{},
}
if _, ok := day31[month]; ok {
return 31
}
// 有30天的月份
day30 := map[int]struct{}{
4: struct{}{},
6: struct{}{},
9: struct{}{},
11: struct{}{},
}
if _, ok := day30[month]; ok {
return 30
}
// 计算是平年还是闰年
if (year%4 == 0 && year%100 != 0) || year%400 == 0 {
// 得出2月的天数
return 29
}
// 得出2月的天数
return 28
}
GO语言查询指定年份指定月份有多少天
于 2021-03-08 15:49:10 首次发布