时间操作

  1. //时间戳转时间格式
  2. time.Unix(1586501854,0).Format("2006-01-02 15:04:05") //2020-04-10 14:57:34
  3. //时间格式转时间戳
  4. //UTC时区版本
  5. t, _ := time.Parse("2006-01-02 15:04:05", "2020-04-10 14:57:34")
  6. t.Unix() //1586530654
  7. //东八区版本
  8. var cstEastZone8 = time.FixedZone("CST", 8*3600)
  9. t, _ := time.ParseInLocation(TIMESTR, "2020-07-19 11:03:40", cstEastZone8)
  10. t.Unix() //1595127820