GAAS GFrame项目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
778 B

  1. package grmi
  2. import (
  3. "LAPP_GAAS_GFrame_BACKEND/utils"
  4. "fmt"
  5. json "github.com/json-iterator/go"
  6. "time"
  7. )
  8. type DateTime time.Time
  9. func (self DateTime) MarshalJSON() ([]byte, error) {
  10. return []byte(fmt.Sprintf("\"%s\"", time.Time(self).Format(URLDateTimeFormat))), nil
  11. }
  12. func (self *DateTime) 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(URLDateTimeFormat, jsonString, utils.TimezoneLocation)
  19. if err != nil {
  20. return err
  21. }
  22. *self = DateTime(result)
  23. return nil
  24. }
  25. func (self *DateTime) Restore() time.Time {
  26. return time.Time(*self)
  27. }
  28. func (self *DateTime) ToString() string {
  29. date := self.Restore()
  30. return date.Format(DatetimeOutFormat)
  31. }