慕妹3146593
使用Go 标准库时间包在 Go 中编写一个函数。例如,package mainimport ( "fmt" "time")func endDate(t time.Time, wd time.Weekday) time.Time { next := int((wd - t.Weekday() + 7) % 7) y, m, d := t.Date() return time.Date(y, m, d+next+1, 0, 0, 0, -1, t.Location())}func main() { now := time.Now().Round(0) fmt.Println(now, now.Weekday()) end := endDate(now, time.Sunday) fmt.Println(end, end.Weekday())}输出:2018-11-08 05:25:01.104445722 -0500 EST Thursday
2018-11-11 23:59:59.999999999 -0500 EST Sunday