广汽安道拓Acura项目MES后台
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.

45 lines
875 B

3 years ago
  1. package grmi
  2. import (
  3. "LAPP_ACURA_MOM_BACKEND/utils"
  4. "fmt"
  5. json "github.com/json-iterator/go"
  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. }
  32. func (self *Time) String() string {
  33. if self == nil {
  34. return ""
  35. }
  36. date := self.Restore()
  37. return date.Format(DateTimeOutFormat)
  38. }