package utils import ( "time" ) var cstZone = time.FixedZone("CST", 8*3600) const ( TimeFormat = "2006-01-02 15:04:05" DateFormat = "2006-01-02" ) func TodayZeroTimeFormat() string { 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 } func MonthDate() string { return NowTime().Format("2006-01") } func MonthDateAdd(month int) string { return NowTime().AddDate(0, month, 0).Format("2006-01") } func TodayZeroAddDays(days int) time.Time { return TodayZero().AddDate(0, 0, days) } func TodayZeroAddDaysDateFormat(days int) string { return TodayZero().AddDate(0, 0, days).Format(DateFormat) } 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) } func NowTime() time.Time { return time.Now().In(cstZone) }