package main import "fmt" func main() { days := CalcDaysFromYearMonth(2021, 9) fmt.Println(days) } func CalcDaysFromYearMonth(year, month int) int8{ /* 根据年月计算天数 */ var days int8 switch month { case 1, 3, 5, 7, 8, 10, 12: days = 31 case 4, 6, 9, 11: days = 30 case 2: if year%4 == 0 { days = 29 // 闰年 } else { days = 28 // 平年 } default: days = -1 } return days }