gitee.com/gricks/utils@v1.0.8/time.go (about) 1 package utils 2 3 import ( 4 "time" 5 ) 6 7 var Now = time.Now 8 9 // Format 10 11 const ( 12 DateLayout = "2006-01-02" 13 TimeLayout = "2006-01-02 15:04:05" 14 ) 15 16 func ParseTime(s string) (time.Time, error) { 17 return time.ParseInLocation(TimeLayout, s, time.Local) 18 } 19 20 func FormatTime(t time.Time) string { 21 return t.Format(TimeLayout) 22 } 23 24 func ParseDate(s string) (time.Time, error) { 25 return time.ParseInLocation(DateLayout, s, time.Local) 26 } 27 28 func FormatDate(t time.Time) string { 29 return t.Format(DateLayout) 30 } 31 32 // Uptime 33 34 var uptime = time.Now() 35 36 func Uptime() time.Time { 37 return uptime 38 }