package tool 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 }