【问题标题】:How to convert timestamp locally according to our location如何根据我们的位置在本地转换时间戳
【发布时间】:2017-07-14 12:17:45
【问题描述】:
startTime := time.Unix(logUserDetail[k].LogTime, 0)
startTimeOfLog := startTime.String()[11:16]

我有时间戳格式的时间,它在 UTC 时区。我想根据我们所在的位置将这个时间转换为当地时区。

logUserDetail[k].LogTime 是时间戳(1499335473)

【问题讨论】:

    标签: go


    【解决方案1】:

    您可以使用(t Time) In() (Golang documentation) 将startTime 转换为使用您当地的时区。

    【讨论】:

      【解决方案2】:

      请检查本地函数的时间结构:https://golang.org/pkg/time/#Time.Local

      package main
      import (
      "fmt"
      "time"
      )
      func main() {
          startTime := time.Now()
          fmt.Println(startTime.Local())
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-15
        • 2021-10-14
        • 2020-05-04
        • 2016-01-14
        • 2012-09-11
        • 2011-02-06
        • 2019-03-09
        • 2017-08-11
        相关资源
        最近更新 更多