dt_automate/damo/damo.go
2025-03-11 15:07:17 +08:00

35 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package damo
import (
"fmt"
"log"
"math"
"time"
)
func Damo() {
startTime, _ := time.Parse("2006-01-02", "2023-01-01") //之前的时间
endTime, _ := time.Parse("2006-01-02", "2023-01-05") //当前时间
// 计算时间段分成一天一段
for current := startTime; current.Before(endTime) || current.Equal(endTime); {
// 当天的开始时间00:00:00
dayStart := time.Date(current.Year(), current.Month(), current.Day(), 0, 0, 0, 0, current.Location())
// 当天的结束时间23:59:59
dayEnd := dayStart.AddDate(0, 0, 1).Add(-1 * time.Nanosecond)
// 如果当前计算的结束时间超过endTime则将endTime作为结束时间
if dayEnd.After(endTime) {
dayEnd = time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 23, 59, 59, 999999999, endTime.Location())
}
fmt.Printf("从 %s 到 %s\n", dayStart.Format("2006-01-02T15:04:05"), dayEnd.Format("2006-01-02T15:04:05"))
// 移动到下一天
current = current.AddDate(0, 0, 1)
}
totalPages := int(math.Floor(float64(610))/float64(200) + 1)
log.Println(totalPages)
log.Println(time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Now().Location()))
}