脚本宝典收集整理的这篇文章主要介绍了golang中使用switch语句根据年月计算天数,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。@H_360_0@
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 }
以上是脚本宝典为你收集整理的golang中使用switch语句根据年月计算天数全部内容,希望文章能够帮你解决golang中使用switch语句根据年月计算天数所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。