2022-04-02 07:55:23 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var cstZone = time.FixedZone("CST", 8*3600)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TimeFormat = "2006-01-02 15:04:05"
|
|
|
|
DateFormat = "2006-01-02"
|
|
|
|
)
|
|
|
|
|
2022-04-26 06:28:41 +00:00
|
|
|
func TodayZeroTimeFormat() string {
|
2022-04-02 07:55:23 +00:00
|
|
|
return TodayZero().Format(TimeFormat)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TodayZeroDateFormat() string {
|
|
|
|
return TodayZero().Format(DateFormat)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ZeroDateFormat(days int) string {
|
|
|
|
return TodayZeroAddDays(days).Format(DateFormat)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TodayZero() time.Time {
|
|
|
|
t := time.Now()
|
|
|
|
tm := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, cstZone)
|
|
|
|
|
|
|
|
//return time.Now().In(cstZone)
|
|
|
|
return tm
|
|
|
|
}
|
|
|
|
|
2022-05-10 07:17:34 +00:00
|
|
|
func MonthDate() string {
|
|
|
|
return NowTime().Format("2006-01")
|
|
|
|
}
|
|
|
|
|
2022-05-13 09:35:10 +00:00
|
|
|
func MonthDateAdd(month int) string {
|
|
|
|
return NowTime().AddDate(0, month, 0).Format("2006-01")
|
|
|
|
}
|
|
|
|
|
2022-04-02 07:55:23 +00:00
|
|
|
func TodayZeroAddDays(days int) time.Time {
|
|
|
|
return TodayZero().AddDate(0, 0, days)
|
|
|
|
}
|
|
|
|
|
2022-04-26 06:28:41 +00:00
|
|
|
func TodayZeroAddDaysDateFormat(days int) string {
|
|
|
|
return TodayZero().AddDate(0, 0, days).Format(DateFormat)
|
|
|
|
}
|
|
|
|
|
2022-04-02 07:55:23 +00:00
|
|
|
func YesterdayZero() time.Time {
|
|
|
|
return TodayZeroAddDays(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Now() time.Time {
|
|
|
|
return time.Now().In(cstZone)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TimeFormatDate(stamp int64) string {
|
|
|
|
return time.Unix(stamp, 0).Format(DateFormat)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Yesterday() time.Time {
|
|
|
|
return TodayAddDays(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TodayAddDays(days int) time.Time {
|
|
|
|
return Now().AddDate(0, 0, days)
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
|
|
|
|
func NowTime() time.Time {
|
|
|
|
return time.Now().In(cstZone)
|
|
|
|
}
|