main.go 721 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. func main() {
  7. fmt.Println("==== Now ====")
  8. ptz(time.Now())
  9. fmt.Println("==== 1996-11-14 00:00:00 +0800 ====")
  10. t1, _ := time.Parse(time.RFC3339, "1996-11-14T00:00:00+08:00")
  11. ptz(t1)
  12. fmt.Println("==== 1996-11-14 00:00:00 +0600 ====")
  13. t2, _ := time.Parse(time.RFC3339, "1996-11-14T00:00:00+06:00")
  14. ptz(t2)
  15. }
  16. func p(t time.Time) {
  17. fmt.Println(t.Year(), t.Month().String(), t.Day(), t.Hour(), t.Minute(), t.Second())
  18. }
  19. func ptz(t time.Time) {
  20. t1 := t
  21. t2 := t1.Local()
  22. t3 := t1.UTC()
  23. l1 := t1.Location()
  24. l2 := t2.Location()
  25. l3 := t3.Location()
  26. fmt.Println("Location", l1, l2, l3)
  27. fmt.Println("Raw:")
  28. p(t1)
  29. fmt.Println("Local:")
  30. p(t2)
  31. fmt.Println("UTC:")
  32. p(t3)
  33. }