|
- package egg_system_rules
-
- import "time"
-
- func Time2String(date time.Time, format string) string {
- if format == "" {
- format = "2006-01-02 15:04:05"
- }
- timeS := date.Format(format)
- if timeS == "0001-01-01 00:00:00" {
- return ""
- }
- return timeS
- }
- func String2Time(timeStr string) time.Time {
- toTime, err := time.ParseInLocation("2006-01-02 15:04:05", timeStr, time.Local)
- if err != nil {
- return time.Now()
- }
- return toTime
- }
-
- // GetDiffDays 获取两个时间相差的天数,0表同一天,正数表t1>t2,负数表t1<t2
- func GetDiffDays(t1, t2 time.Time) int {
- t1 = time.Date(t1.Year(), t1.Month(), t1.Day(), 0, 0, 0, 0, time.Local)
- t2 = time.Date(t2.Year(), t2.Month(), t2.Day(), 0, 0, 0, 0, time.Local)
-
- return int(t1.Sub(t2).Hours() / 24)
- }
|