Guest User

Untitled

a guest
Sep 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. {
  2. "name" : "hello",
  3. "lastModified" : 1438167001716
  4. }
  5.  
  6. type Model struct {
  7. Name string `json:"name"`
  8. Lastmodified time.Time `json:"lastModified"`
  9. }
  10.  
  11. type Model struct {
  12. Name string `json:"name"`
  13. Millis int64 `json:"lastModified"`
  14. }
  15.  
  16. func (m Model) Lastmodified() time.Time {
  17. return time.Unix(0, m.Millis * int64(time.Millisecond))
  18. }
  19.  
  20. type Model struct {
  21. Name string `json:"name"`
  22. Lastmodified javaTime `json:"lastModified"`
  23. }
  24.  
  25. type javaTime time.Time
  26.  
  27. func (j *javaTime) UnmarshalJSON(data []byte) error {
  28. millis, err := strconv.ParseInt(string(data), 10, 64)
  29. if err != nil {
  30. return err
  31. }
  32. *j = javaTime(time.Unix(0, millis * int64(time.Millisecond)))
  33. return nil
  34. }
Add Comment
Please, Sign In to add comment