直接上代码
loc, _ := time.LoadLocation(getConfig("common", "timezone"))
// 正常代码 直接写时间字符串是不会出问题的
toBeCharge := "2006-01-02 15:04:05"
// 错误代码,因为字符串中出现\r\n字符才会出现 -62135596800 的问题
toBeCharge := strings.Trim("2006-01-02 15:04:05
", "\r\n")
timeLayout := "2006-01-02 15:04:05"
// 如果有问题启用 _ 把错误打出来看看对症下药
timestamp, _ := time.ParseInLocation(timeLayout, toBeCharge, loc)
备注:如果您有更好的解决方案,欢迎和我交流!