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.
37 lines
1.2 KiB
37 lines
1.2 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
|
|
}
|
|
|