Skip to content

Instantly share code, notes, and snippets.

View letoan96's full-sized avatar

Le Tran The Toan letoan96

View GitHub Profile
@letoan96
letoan96 / custom_time.go
Created May 13, 2021 11:51 — forked from lummie/custom_time.go
Golang custom date / time formats when marshalling to JSON
// CustomTime provides an example of how to declare a new time Type with a custom formatter.
// Note that time.Time methods are not available, if needed you can add and cast like the String method does
// Otherwise, only use in the json struct at marshal/unmarshal time.
type CustomTime time.Time
const ctLayout = "2006-01-02 15:04:05 Z07:00"
// UnmarshalJSON Parses the json string in the custom format
func (ct *CustomTime) UnmarshalJSON(b []byte) (err error) {