根据time package
time package 中关于Parse Function的说明如下:
In the absence of a time zone indicator, Parse returns a time in UTC.
也就是说通过Parse解析时间字符串,自动采用UTC(协调世界时)
但UTC的时间不等于本地时间,怎么办?
使用time.Date函数 (func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time)
代码如下:
t, err := time.Parse("2006-01-02T15:04", s)
if err == nil {
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), time.Local)
return &t
}
参考资料: