GAAS 广汽安道拓GFrame金属件MOM项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
511 B

  1. package grmi
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "time"
  6. )
  7. type DateTime time.Time
  8. func (self DateTime) MarshalJSON() ([]byte, error) {
  9. return []byte(fmt.Sprintf("\"%s\"", time.Time(self).Format(URLDateTimeFormat))), nil
  10. }
  11. func (self *DateTime) UnmarshalJSON(data []byte) error {
  12. var jsonString string
  13. err := json.Unmarshal(data, &jsonString)
  14. if err != nil {
  15. return err
  16. }
  17. result, err := time.Parse(URLDateTimeFormat, jsonString)
  18. if err != nil {
  19. return err
  20. }
  21. *self = DateTime(result)
  22. return nil
  23. }