35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
![]() |
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()))
|
|||
|
}
|