简体   繁体   English

Golang:具有自定义时区的分叉进程

[英]Golang: fork process with custom timezone

In Golang is it possible to fork a child process and force it to use a shifted timezone from UTC?在 Golang 中是否可以分叉一个子进程并强制它使用从 UTC 偏移的时区? For instance, my server's timezone is UTC, and I want the forked process to use UTC+5.例如,我的服务器的时区是 UTC,我希望分叉的进程使用 UTC+5。

The answers to this question will give you more details ( Setting timezone globally in golang ) but ultimately you can simply set the TZ environment variable and then execute the command:这个问题的答案将为您提供更多详细信息( 在 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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM