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()) }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报