【发布时间】:2023-02-08 05:33:12
【问题描述】:
我有一个表,其中 Created_At 字段为“带时区的时间戳”
当我选择行时,我有带有 CreatedAt 的实体和我所在位置的时区,我想将其设置为 UTC。
type app struct {
ID uuid.UUID
CreatedAt time.Time
}
db, err := gorm.Open(
postgres.Open(databaseURL),
&gorm.Config{},
)
if err != nil {
panic(err)
}
a := &app{}
db.Table("applications").Take(a)
fmt.Println(a.CreatedAt)
它打印“2023-02-01 11:26:29.554589 +0300 MSK” 我想要“2023-02-01 08:26:29.554589 +0000 UTC”
有一些选择吗(gorm-v2)?
顺便说一句,gorm-v1 检索为 UTC。和 gorm-v2 - 在当前位置
【问题讨论】: