go - 如何通过 utc 偏移量加载位置
问题描述
我想通过 UTC 偏移量加载位置,例如
func main() {
L, err := time.LoadLocation("UTC+8")
if err != nil {
panic(err)
}
fmt.Println(L)
}
代码恐慌:panic: unknown time zone UTC+8
如何通过 UTC 偏移量(不是本地或 UTC,而是另一个位置)获取位置对象,而不必以 IANA 时区格式指定它,例如“America/New_York”
我的目的很简单:我有一个在固定位置运行的 Web 服务器,我可以轻松地获取本地时间。现在我想根据访问者的位置(由 url 参数发送,例如http://myserver.com/do_something?timezone=-8
)进行时间计算。
解决方案
我找到了:
time.FixedZone(name string, offset int)
这将创建一个具有给定名称(这并不重要)和偏移量的位置。
推荐阅读
- ios - 应用程序终止或在后台时在 IOS 设备上进行实时位置跟踪
- python - 如何使用 Anaconda 提示符安装 Rasa NLU
- azure - 如何获取 azure blob 的复制状态
- java - 在 JTextPane 中转换为大写或小写时,文本样式和格式正在发生变化
- mysql - 从 MYSQL 中删除超过 X 天的数据,Unix 时间以毫秒为单位
- php - 无法在 1.7.4.3 上删除产品组合
- ios - 可能丢失钥匙串访问权限
- javascript - 无法在 PDFjs 中为 pdf.worker.js 指定自定义路径
- angularjs - AngularJS 加载资源失败:服务器响应状态为 403 ()
- thingsboard - Thingboard:从内部数据库获取资产 ID