Skip to content

Instantly share code, notes, and snippets.

@ankur22
Created March 7, 2022 10:50
Show Gist options
  • Save ankur22/2dfc92e36a01ab4f7b6fb146bb716dee to your computer and use it in GitHub Desktop.
Save ankur22/2dfc92e36a01ab4f7b6fb146bb716dee to your computer and use it in GitHub Desktop.
Parse an iso timestamp from json straight into a time type
package main
import (
"encoding/json"
"fmt"
"time"
)
type someType struct {
Time *time.Time `json:"time"`
}
func main() {
body := `{"time":"2022-03-07T10:36:50Z"}`
s := someType{}
err := json.Unmarshal([]byte(body), &s)
if err != nil {
panic(err.Error())
}
fmt.Println(s.Time)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment