zoukankan      html  css  js  c++  java
  • Go输出日期之间所有日期(按天切分日期)

    
    func main() {
    	fmt.Println(splitDate("2021-03-09", "2021-04-06", "2006-01-02")) // [2021-03-09 2021-03-10 2021-03-11 2021-03-12 2021-03-13 2021-03-14 2021-03-15 2021-03-16 2021-03-17 2021-03-18 2021-03-19 2021-03-20 2021-03-21 2021-03-22 2021-03-23 2021-03-24 2021-03-25 2021-03-26 2021-03-27 2021-03-28 2021-03-29 2021-03-30 2021-03-31 2021-04-01 2021-04-02 2021-04-03 2021-04-04 2021-04-05 2021-04-06]
    }
    
    func splitDate(beginDate, endDate, format string) []string {
    	bDate, _ := time.ParseInLocation(format, beginDate, time.Local)
    	eDate, _ := time.ParseInLocation(format, endDate, time.Local)
    	day := int(eDate.Sub(bDate).Hours() / 24)
    	dlist := make([]string, 0)
    	dlist = append(dlist, beginDate)
    	for i := 1; i < day; i++ {
    		result := bDate.AddDate(0, 0, i)
    		dlist = append(dlist, result.Format(format))
    	}
    	dlist = append(dlist, endDate)
    	return dlist
    }
    
    学生浅薄 望众师指点
  • 相关阅读:
    Python-pymysql
    MySQL学习(3)
    MySQL学习(1)
    MySQL与PostgreSQL哪个更好?
    svn与git区别
    journalctl常用命令
    Spring Cloud 生产环境性能优化
    springcloud优雅停止上下线与熔断
    istio基础详解
    微服务的全链路监控
  • 原文地址:https://www.cnblogs.com/Nihility/p/14695646.html
Copyright © 2011-2022 走看看