package main import ( "fmt" "testing" "time" ) func TestGetMonth(t *testing.T) { utcZone := time.FixedZone("UTC", 0) time.Local = utcZone //today := time.Now().Add(8 * time.Hour) endTime := time.Now().Add(8 * time.Hour) startTime := endTime.AddDate(0, 0, -10) //fmt.Println(startTime, endTime) for startTime.Before(endTime.AddDate(0, 0, 1)) { //fmt.Println(startTime) fmt.Println(fmt.Sprintf("%s 16:00:00.000", startTime.AddDate(0, 0, -1).Format(DateFmtYYYYMMDD))) fmt.Println(fmt.Sprintf("%s 16:00:00.000", startTime.Format(DateFmtYYYYMMDD))) fmt.Println("------------") if startTime.Equal(endTime) { fmt.Println("2222222") } startTime = startTime.AddDate(0, 0, 1) } fmt.Println(startTime) }