go - 如何在 Go 语言中获取指定时区的 Hour()?
问题描述
当我使用 Hour() 函数时,它会一直返回 UTC 小时。如何获得指定时区的正确小时数?谢谢!
解决方案
只需使用In()
功能,它应该可以工作。例如:
package main
import (
"fmt"
"time"
)
func main() {
loc, _ := time.LoadLocation("Europe/Berlin")
t := time.Now().In(loc)
fmt.Println(t.Hour())
}
推荐阅读
- java - 嗨,我如何检查在 java 中接受数字、字符和特殊字符的正则表达式
- sql - sql - 在括号之间获取文本
- javascript - 使用 Tailwind 更改 min-h-full 的值或添加类以设置 min-height
- c++ - 如何将 -std=c++11 配置为默认编译器?
- hyperledger-fabric - 什么情况会导致fabric网络出现状态分叉
- ios - ios上的颤振蓝牙问题
- sql - 尝试在 azure 中创建应用程序,它将基于 SQL 服务器中的 DML 操作将 xml 发布到 URL
- python - 与 Django 1.6.11 兼容的 Elastic APM 版本是多少?
- nativescript - event.object.lastVisionImage.getBitmap 不是函数
- spring - HttpHeaders 在 spring5 更改中发生更改,导致 API 失败 400