go_dreamfactory/utils/time.go
2022-10-11 09:39:25 +08:00

56 lines
1.3 KiB
Go

package utils
import (
"fmt"
"time"
"github.com/jinzhu/now"
)
// 判断时间点处于今天
func IsToday(d int64) bool {
tt := time.Unix(d, 0)
now := time.Now()
return tt.Year() == now.Year() && tt.Month() == now.Month() && tt.Day() == now.Day()
}
//判断是否大于1周
func IsAfterWeek(d int64) bool {
tt := time.Unix(d, 0)
nowt := time.Now()
if !tt.Before(nowt) {
return false
}
at := now.With(tt).AddDate(0, 0, 7).Unix()
return nowt.Unix() >= at
}
// 获取当前时间戳下一天0点时间戳
func GetZeroTime(curTime int64) int64 {
currentTime := time.Unix(curTime, 0)
startTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location())
return startTime.Unix() + 86400 //3600*24
}
func IsYestoday(timestamp int64) bool {
tt := time.Unix(timestamp, 0)
yesTime := time.Now().AddDate(0, 0, -1)
return tt.Year() == yesTime.Year() && tt.Month() == yesTime.Month() && tt.Day() == yesTime.Day()
}
func MatrixingHour(beginTime string) {
location, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
return
}
myConfig := &now.Config{
WeekStartDay: time.Monday,
TimeLocation: location,
TimeFormats: []string{"2006-01-02 15:04:05"},
}
t, _ := myConfig.Parse(beginTime)
fmt.Println(t)
}