Dong.Ge

左手代码 右手江湖

golang 时间加n个月

东哥's Avatar 2019-07-11

1
2
3
4
5
6
7
8
9
10
11
var loc *time.Location
var err error
loc, err = time.LoadLocation("Asia/Shanghai")
if err != nil {
return
}
t := time.Now().In(loc)
//year, month, today := t.Date()
year, month, today := 2019, time.Month(2), 28
thisMonthFirstDay := time.Date(year, month, today, 0, 0, 0, 0, t.Location())
ok := thisMonthFirstDay.AddDate(0, +6, 0).Format("2006-01-02")
本文最后更新于 天前,文中所描述的信息可能已发生改变