Skip to content

Instantly share code, notes, and snippets.

@trietphm
Created February 23, 2016 06:48
Show Gist options
  • Save trietphm/adf48f2ca31504e601ab to your computer and use it in GitHub Desktop.
Save trietphm/adf48f2ca31504e601ab to your computer and use it in GitHub Desktop.
package views
import (
"encoding/json"
"time"
)
type Timestamp time.Time
func (t Timestamp) MarshalJSON() ([]byte, error) {
str := time.Time(t).UTC().Format("2006-01-02T15:04:05.000Z")
return json.Marshal(str)
}
func (t *Timestamp) String() string {
return time.Time(*t).String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment