简体   繁体   中英

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? For instance, my server's timezone is UTC, and I want the forked process to use 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:

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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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