dtp/util/util.go

26 lines
537 B
Go
Raw Normal View History

2024-08-15 04:56:58 +08:00
package util
import (
"fmt"
2024-08-20 18:08:35 +08:00
"math"
2024-08-15 04:56:58 +08:00
"time"
)
// 获取0点时间戳
func GetDayStartTimeStamp(t time.Time) int64 {
loc, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
loc = time.FixedZone("CST", 8*3600)
}
timeStr := fmt.Sprintf("%02d-%02d-%02d 00:00:00", t.Year(), t.Month(), t.Day())
duetimecst, err := time.ParseInLocation("2006-1-2 15:04:05", timeStr, loc)
if err != nil {
fmt.Printf("parse error : %v\n", err)
}
return duetimecst.Unix()
}
2024-08-20 18:08:35 +08:00
func RoundUp(num float64) int64 {
return int64(math.Ceil(num))
}