gpt4 book ai didi

database - 如何将 +0000 UTC 转换为 +0100 CET

转载 作者:行者123 更新时间:2023-12-01 22:44:34 25 4
gpt4 key购买 nike

我编写了一个基于当前时间返回摘要的程序,但是我遇到了一个问题,即当前时间是我的本地格式,但是我从数据库中获取的开始和结束时间在不同的时区,所以在示例中而不是事件持续时间为 16:00 至 23:59 持续时间为 17:00 至 00:59(时差一小时)

currenttime 2020-02-12 19:59:56.161262078 +0100 CET m=+0.001121940
eventstart 2019-02-13 16:00:00 +0000 UTC
eventend 2019-02-13 23:59:00 +0000 UTC

有没有办法“解析” eventstart 和 eventend 在同一个时区?

最佳答案

如果事件存储在某个地方(在数据库中),它将被保存为来自 UTC 的时间戳。当你想显示 本地 时间在不同的时区,你可以使用这样的东西:

startTime := time.Now()
// startTime will be in UTC and the timezone
// will be set to whatever your local timezone is

// load the location you want to display the time in
loc, _ := time.LoadLocation("Europe/Berlin")

// set timezone and display:
timeToDisplay := startTime.In(loc).String()
fmt.Println(timeToDisplay)

关于database - 如何将 +0000 UTC 转换为 +0100 CET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60203373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com