根据输入的日期(年月日)判断是星期几——golang实现

逍遥子_ ·
在你的基础上,导出每周x的日期。 ``` package main import ( "fmt" "time" ) func GetBetweenDates(sdate, edate string) []string { d := []string{} timeFormatTpl := "2006-01-02" date, err := time.Parse(timeFormatTpl, sdate) if err != nil { return d } date2, err := time.Parse(timeFormatTpl, edate) if err != nil { return d } if date2.Before(date) { return d } timeFormatTpl = "2006-01-02" date2Str := date2.Format(timeFormatTpl) for { if date.Weekday() == time.Monday && date.Format(timeFormatTpl) != date2Str { dateStr := date.Format(timeFormatTpl) d = append(d, dateStr) date = date.AddDate(0, 0, 1) } else if date.Format(timeFormatTpl) == date2Str { break } else { date = date.AddDate(0, 0, 1) } } return d } func main() { dates := GetBetweenDates("2018-06-04", "2021-02-22") fmt.Println(dates) } ```
#1