如何根据我们的位置将时间戳转换为本地时间?

huangapple go评论78阅读模式
英文:

How to convert timestamp locally according to our location

问题

startTime := time.Unix(logUserDetail[k].LogTime, 0)
startTimeOfLog := startTime.String()[11:16]

我有一个时间戳格式的时间,它是以UTC时区表示的。我想将这个时间转换为我们所在地的本地时区。

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

英文:
startTime := time.Unix(logUserDetail[k].LogTime, 0)
startTimeOfLog := startTime.String()[11:16]

I have time in timestamp format and it is in UTC time zone. I want to convert this time to the local timezone according to our location.

logUserDetail[k].LogTime is in timestamp(1499335473)

答案1

得分: 1

你可以使用(t Time) In()Golang文档)将startTime转换为你所在的本地时区。

英文:

You can use (t Time) In() (Golang documentation) to convert startTime to use your local timezone.

答案2

得分: 0

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

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

Please check the Local function for time structs: https://golang.org/pkg/time/#Time.Local

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

huangapple
  • 本文由 发表于 2017年7月9日 21:39:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/44997022.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定