Created
March 7, 2022 10:50
-
-
Save ankur22/2dfc92e36a01ab4f7b6fb146bb716dee to your computer and use it in GitHub Desktop.
Parse an iso timestamp from json straight into a time type
This file contains 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 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