当前位置:网站首页>Golang foundation - the time data inserted by golang into MySQL is inconsistent with the local time

Golang foundation - the time data inserted by golang into MySQL is inconsistent with the local time

2022-07-05 08:50:00 The hunter is eating meat

Problem description

golang towards mysql When inserting the data of the time field , The time value before insertion is correct , After inserting , In the database Time value Than Time value before insertion Less 8 Hours .

analysis

Default time zone and Caused by inconsistent local time zones .

analytic method

database URL Add... After configuration parseTime=true&loc=Local Parameters can be solved .

func init() {
    
	Db, err = sql.Open("mysql", "root:[email protected](localhost:3306)/testDB?parseTime=true&loc=Local")
	if err != nil {
    
		panic(err.Error())
	}
}
原网站

版权声明
本文为[The hunter is eating meat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050841011606.html