Home > Blockchain >  Golang: fork process with custom timezone
Golang: fork process with custom timezone

Time:12-29

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.

CodePudding user response:

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)
}
  •  Tags:  
  • go
  • Related