Last active
April 16, 2018 14:44
-
-
Save bylatt/c8746ac156b33c2f5a9c59015e6b08db to your computer and use it in GitHub Desktop.
Custom time format in json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "time" | |
| ) | |
| type Message struct { | |
| Text string | |
| CreatedAt time.Time `json:"created_at"` | |
| } | |
| func main() { | |
| message := Message{Text: "Hello", CreatedAt: time.Now()} | |
| jsonByte, _ := json.Marshal(message) | |
| fmt.Println(string(jsonByte)) | |
| } | |
| // Output: {"Text":"Hello","created_at":"2018-04-16T21:41:49.256442092+07:00"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment