Your issue may already be reported! Please search on the issue track before creating one.

What version of Go are you using (go version)?

1.8

Which database and its version are you using?

mysql 5.7

Please provide a complete runnable program to reproduce your issue. IMPORTANT

Need to runnable with GORM's docker compose config or please provides your config.


type PayCompanyInfo struct {
    Id                int            `db:"id"`
    Name              string`db:"name"`
    CreateTime        time.Time      `db:"create_time"`
    UpdateTime        time.Time      `db:"update_time"`
}
func SaveOrUpdateCompany(company *PayCompanyInfo) error {

    result := CompanyOrm.Save(&company)
    if result.Error != nil {
        return result.Error
    }

    return nil

}

func main() {
      company := PayCompanyInfo{}
      company.Name = "a"
      company.CreateTime = time.Now() //假设是2018-01-01 00:00:00
     SaveOrUpdateCompany(company) 
     SaveOrUpdateCompany(company) //这次更新后会变成是2018-01-01 08:00:00

}

数据库连接是 connectStr := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&loc=Asia%%2FShanghai", conf.Conf.UserName, conf.Conf.Password, conf.Conf.Host, conf.Conf.Port, conf.Conf.Name)

请问是什么问题造成的?

Comment From: shen-xianpeng

找到原因了 是parseTime=true&loc=Local一个连接加了,一个连接没加 读取时间有的带时区,有的没带时区

Comment From: zhguokai

@shen-xianpeng 什么意思

Comment From: shen-xianpeng

我混用了两个库 连接配置时一个没指定locale 一个指定了locale, 导致从一个库读取的model用另一个库保存,导致保存时间出现了问题。我的用法设置的问题

Comment From: matthew188

我混用了两个库 连接配置时一个没指定locale 一个指定了locale, 导致从一个库读取的model用另一个库保存,导致保存时间出现了问题。我的用法设置的问题

我用了一个库,还是同样的问题