time_offset.go 452 B

1234567891011121314151617181920212223242526272829
  1. package mhayaTime
  2. import "time"
  3. var (
  4. offsetTime time.Duration //全局偏移时间
  5. offsetLocation *time.Location //全局偏移时区
  6. )
  7. func init() {
  8. SetOffsetLocation("Local")
  9. }
  10. func AddOffsetTime(t time.Duration) {
  11. offsetTime = t
  12. }
  13. func SubOffsetTime(t time.Duration) {
  14. offsetTime = -t
  15. }
  16. func SetOffsetLocation(name string) (err error) {
  17. offsetLocation, err = time.LoadLocation(name)
  18. if err != nil {
  19. return err
  20. }
  21. return nil
  22. }