Skip to content

Instantly share code, notes, and snippets.

@bylatt
Last active April 16, 2018 14:44
Show Gist options
  • Select an option

  • Save bylatt/c8746ac156b33c2f5a9c59015e6b08db to your computer and use it in GitHub Desktop.

Select an option

Save bylatt/c8746ac156b33c2f5a9c59015e6b08db to your computer and use it in GitHub Desktop.
Custom time format in json
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