You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 用法一,使用carbon.GormModel自动维护id、created_at、updated_at、deleted_at
type User struct {
carbon.GormModel
Name string `json:"name"`
Age int `json:"age"`
Birthday carbon.ToDateTimeString `json:"birthday"`
}
user := User {
Name: "勾国印"
Age: 18
Birthday: "2012-09-09 00:00:00" // 这里字符串无法赋值给ToDateString类型,结构体赋值也缺少必要逗号
}
// 用法二,不使用carbon.GormModel
type User struct {
Name string `json:"name"`
Age int `json:"age"`
Birthday carbon.ToDateString `json:"birthday"`
CreatedAt carbon.ToDateTimeString `json:"created_at"`
UpdatedAt carbon.ToTimeString `json:"updated_at"`
DeletedAt carbon.ToTimestamp `json:"deleted_at"`
}
user := User {
Name: "勾国印"
Age: 18
Birthday: "2012-09-09 00:00:00" // 这里字符串无法赋值给ToDateString类型,结构体赋值也缺少必要逗号
}
代码示例有明显的错误
另外在使用
gorm
时,carbon.ToDateString
类型的字段无法直接赋值carbon.New().Now()
,两者之间的转换无法无缝衔接貌似跟直接用
time.Time
唯一的区别就是支持了几种不同的时间格式The text was updated successfully, but these errors were encountered: