一般在获取到时间字符串,需要将时间字符串格式化为golang的"time.Time"对象的时候,通常有2个函数,分别是. time.Parse(layout, value string) (Time, error) time.ParseInLocation(layout, value string, loc *Location) (Time, error) 两个函数相比,不一样的地方在于,Parse()函数解析的时候,会默为UTC时间,获取的Time对象转换为Unix()对象后,会比当…
先了解下time类型: type Time struct { // sec gives the number of seconds elapsed since // January 1, year 1 00:00:00 UTC. sec int64 // nsec specifies a non-negative nanosecond // offset within the second named by Seconds. // It must be in the range [0, 9999…
参考: https://golangcode.com/checking-if-date-has-been-set/ https://stackoverflow.com/questions/20924303/date-time-comparison-in-golang // utc life loc, _ := time.LoadLocation("UTC") // setup a start and end time createdAt := time.Now().In(loc).Ad…