golang 根据时间范围获取顺序日期列表
package main
import (
"fmt"
"time"
)
func Get_Time(start_time, stop_time string) (args []string) {
tm1, _ := time.Parse("2006-01-02", start_time)
tm2, _ := time.Parse("2006-01-02", stop_time)
//fmt.Println(tm1.Unix(),tm2.Unix())
sInt := tm1.Unix()
eInt := tm2.Unix()
for {
sInt += 86400
st := time.Unix(sInt, 0).Format("20060102")
args = append(args,st)
if sInt > eInt {
return
}
}
}
func main() {
fmt.Println(Get_Time("2020-08-20", "2020-08-27"))
}
返回
[20200821 20200822 20200823 20200824 20200825 20200826 20200827]