Created
December 8, 2014 01:56
-
-
Save akhenakh/ece34e80bea4740a05a7 to your computer and use it in GitHub Desktop.
time.Time timestamp JSON in Go
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
type JSONTime time.Time | |
func (t JSONTime) MarshalJSON() ([]byte, error) { | |
stamp := fmt.Sprintf("\"%d\"", time.Time(t).Unix()) | |
return []byte(stamp), nil | |
} | |
// If you are using gob you need to redefine MarshalBinary | |
func (t JSONTime) MarshalBinary() ([]byte, error) { | |
return time.Time(t).MarshalBinary() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment