Skip to content

gorm写入数据库后时间差8小时

Published: at 11:01 AM | 1 min read

这个很明显是时区的问题,首先检查一下数据库连接的uri,是否包含如下参数:

parseTime=true&loc=Local

重新连接数据库就可以了,如果还不行那你可能要看一下系统环境设置了。

官方文档链接

loc
Type:           string
Valid Values:   <escaped name>
Default:        UTC
Sets the location for time.Time values (when using parseTime=true). "Local" sets the system's location. See time.LoadLocation for details.

Note that this sets the location for time.Time values but does not change MySQL's time_zone setting. For that see the time_zone system variable, which can also be set as a DSN parameter.