Go语言使用Beego的ORM插入Mysql后,时区不一致的解决方案

一、解决方案:

方案一:

orm.Debug = false
	orm.DefaultTimeLoc = time.UTC
	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql", "root:LPET6Plus@tcp(127.0.0.1:18283)/lpet6plusdb?charset=utf8&loc=Local")
	orm.RegisterModel(new(Versions))
	orm.RegisterModel(new(Regversions))
	orm.RegisterModel(new(Osversions))

方案二:

func init() {

	var datasource = "db_test:dbtestqwe321@tcp(127.0.0.1:3306)/db_test?charset=utf8&loc=Asia%2FShanghai" 
	orm.RegisterDataBase("default", "mysql", datasource, 30)

	orm.DefaultTimeLoc = time.Local
	orm.RegisterModel(new(Category), new(Topic))

	orm.RunSyncdb("default", false, true)
}

  

转载于:https://www.cnblogs.com/songxingzhu/p/5364092.html

你可能感兴趣的:(Go语言使用Beego的ORM插入Mysql后,时区不一致的解决方案)