代码拉取完成,页面将自动刷新
package gocalendar
import (
"time"
)
// GregorianMonthDays 公历某月的总天数
func GregorianMonthDays(year, month int) int {
md := [12]int{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
if month == 2 && IsLeapYear(year) {
return 29
}
return md[month - 1]
}
// IsLeapYear 给定的公历年year是否是闰年
func IsLeapYear(year int) bool {
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}
// BeginningOfMonth 计算出t所在月份的首日
//
// 时hour,分minute,秒second与t对应的值一样
func BeginningOfMonth(t time.Time) time.Time {
day := t.Day()
day--
return t.AddDate(0,0,-day)
}
// EndOfMonth 计算出t所在月份的最后一日
//
// 时hour,分minute,秒second与t对应的值一样
func EndOfMonth(t time.Time) time.Time {
nextMonthTime := t.AddDate(0,1,0)
return BeginningOfMonth(nextMonthTime).AddDate(0,0,-1)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。