duancoubeng5909 2018-08-22 11:29
浏览 43
已采纳

如何用Go语言获取指定时区的Hour()? [关闭]

When I use Hour() function, it keeps return the UTC hour. How to get the correct Hour number with specified Timezone? Thanks!

  • 写回答

1条回答 默认 最新

  • douguiyan9164 2018-08-22 11:37
    关注

    Just use In() function and it should work. For example:

    package main
    
    import (
        "fmt"
        "time"
    )
    
    func main() {
        loc, _ := time.LoadLocation("Europe/Berlin")
    
        t := time.Now().In(loc)
        fmt.Println(t.Hour())
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?