How to parse non standard time format from json

后端 未结 3 1512
梦如初夏
梦如初夏 2020-12-24 03:32

lets say i have the following json

{
    name: \"John\",
    birth_date: \"1996-10-07\"
}

and i want to decode it into the following struct

3条回答
  •  遥遥无期
    2020-12-24 03:48

    If there are lots of struct and you just implement custom marshal und unmarshal functions, that's a lot of work to do so. You can use another lib instead,such as a json-iterator extension jsontime:

    import "github.com/liamylian/jsontime"
    
    var json = jsontime.ConfigWithCustomTimeFormat
    
    type Book struct {
        Id        int           `json:"id"`
        UpdatedAt *time.Time    `json:"updated_at" time_format:"sql_date" time_utc:"true"`
        CreatedAt time.Time     `json:"created_at" time_format:"sql_datetime" time_location:"UTC"`
    }
    

提交回复
热议问题