我试图在特定时间触发工人。问题是我需要知道那个小时服务器的相对时间是多少。客户希望在洛杉矶时间每天晚上 8 点触发工作人员,因此我必须使其具有足够的动态性,以使其花费服务器一小时,计算洛杉矶该小时的等效时间。我也在使用碳,但是有没有内置的功能呢?还是有任何已知的例程来处理它?
1 回答
米脂
TA贡献1836条经验 获得超3个赞
time.LoadLocation并且time.In是您需要的两个功能。以下代码是从time.LoadLocation示例中复制和修改的:
func main() {
location, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
panic(err)
}
timeInUTC := time.Date(2018, 8, 30, 12, 0, 0, 0, time.UTC)
fmt.Println(timeInUTC.In(location))
now := time.Now()
timeThere := time.Date(now.Year(), now.Month(), now.Day(), 8, 0, 0, 0, location)
timeHere := timeThere.In(time.Now().Location())
fmt.Println(timeHere)
}
- 1 回答
- 0 关注
- 182 浏览
添加回答
举报
0/150
提交
取消
