英文:
Golang: fork process with custom timezone
问题
在Golang中,是否可以fork一个子进程并强制其使用与UTC不同的时区?例如,我的服务器时区是UTC,我希望fork的进程使用UTC+5时区。
英文:
In Golang is it possible to fork a child process and force it to use a shifted timezone from UTC? For instance, my server's timezone is UTC, and I want the forked process to use UTC+5.
答案1
得分: 2
这个问题的答案将为您提供更多详细信息(https://stackoverflow.com/questions/54363451/setting-timezone-globally-in-golang),但最终您可以简单地设置TZ
环境变量,然后执行以下命令:
cmd := exec.Command("myprogram")
cmdtz := "TZ=America/New_York"
cmd.Env = append(os.Environ(), cmdtz)
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
英文:
The answers to this question will give you more details (https://stackoverflow.com/questions/54363451/setting-timezone-globally-in-golang) but ultimately you can simply set the TZ
environment variable and then execute the command:
cmd := exec.Command("myprogram")
cmdtz := "TZ=America/New_York"
cmd.Env = append(os.Environ(), cmdtz)
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论