苏州瑞玛APS项目web后台
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.

37 lines
749 B

  1. package grmi
  2. import (
  3. "fmt"
  4. json "github.com/json-iterator/go"
  5. "leit.com/LAPP_CHEERSSON_BACKEND/utils"
  6. "time"
  7. )
  8. type Time time.Time
  9. func (self Time) MarshalJSON() ([]byte, error) {
  10. return []byte(fmt.Sprintf("\"%s\"", time.Time(self).Format(URLTimeFormat))), nil
  11. }
  12. func (self *Time) UnmarshalJSON(data []byte) error {
  13. var jsonString string
  14. err := json.Unmarshal(data, &jsonString)
  15. if err != nil {
  16. return err
  17. }
  18. result, err := time.ParseInLocation(URLTimeFormat, jsonString, utils.TimezoneLocation)
  19. if err != nil {
  20. return err
  21. }
  22. *self = Time(result)
  23. return nil
  24. }
  25. func (self *Time) Restore() time.Time {
  26. return time.Time(*self)
  27. }
  28. func (self *Time) ToString() string {
  29. date := self.Restore()
  30. return date.Format(TimeOutFormat)
  31. }