You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.8 KiB
47 lines
1.8 KiB
package utils
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
func GetTimeRangeByMinute(durationMinute int) (start, stop string) {
|
|
|
|
start = time.Now().Add(time.Minute * -1 * time.Duration(durationMinute)).Format("2006-01-02T15:04:00+08:00")
|
|
stop = time.Now().Format("2006-01-02T15:04:00+08:00")
|
|
return
|
|
}
|
|
|
|
func GetTimeRangeByHour(durationHour int) (start, stop string) {
|
|
|
|
start = time.Now().Add(time.Hour * time.Duration(durationHour)).Truncate(time.Hour).Format("2006-01-02T15:00:00.000+08:00")
|
|
stop = time.Now().Truncate(time.Hour).Format("2006-01-02T15:00:00.000+08:00")
|
|
return
|
|
}
|
|
|
|
func GetTimeRangeBy10min() (start, stop string) {
|
|
now := time.Now()
|
|
m := now.Minute() % 10
|
|
startTime := now.Add(time.Minute * -1 * time.Duration(m))
|
|
start = startTime.Add(time.Minute * -10).Format("2006-01-02T15:04:00.000+08:00")
|
|
stop = startTime.Format("2006-01-02T15:04:00.000+08:00")
|
|
return
|
|
}
|
|
func GetTimeRangeBy10minByOffset(offsetMin int) (start, stop string) {
|
|
offset := time.Duration(offsetMin) * time.Minute
|
|
now := time.Now().Add(offset)
|
|
m := now.Minute() % 10
|
|
startTime := now.Add(time.Minute * -1 * time.Duration(m))
|
|
start = startTime.Add(time.Minute * -10).Format("2006-01-02T15:04:00.000+08:00")
|
|
stop = startTime.Format("2006-01-02T15:04:00.000+08:00")
|
|
return
|
|
}
|
|
|
|
func GetTimeRangeBy1minByOffset(offsetMin int) (start, stop string) {
|
|
offset := time.Duration(offsetMin) * time.Minute
|
|
now := time.Now().Add(offset)
|
|
m := now.Second() // 获取当前时间的秒数,1分钟的偏移点
|
|
startTime := now.Add(time.Second * -1 * time.Duration(m)) // 调整到当前分钟的开始
|
|
start = startTime.Format("2006-01-02T15:04:00.000+08:00") // 格式化为所需的时间字符串
|
|
stop = startTime.Add(time.Minute).Format("2006-01-02T15:04:00.000+08:00") // 结束时间是当前分钟的下一分钟
|
|
return
|
|
}
|
|
|