Skip to content

time: Now doesn't update when timezone is changed #46417

@tommyblue

Description

@tommyblue

What version of Go are you using (go version)?

$ go version
go version go1.16.4 linux/amd64

Does this issue reproduce with the latest release?

it's the latest release

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/tommyblue/src/go/bin"
GOCACHE="/home/tommyblue/.cache/go-build"
GOENV="/home/tommyblue/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tommyblue/src/go/pkg/mod"
GOOS="linux"
GOPATH="/home/tommyblue/src/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/tommyblue/dev/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/tommyblue/dev/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2846216330=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Changing the system timezone with timedatectl set-timezone <tz> doesn't change the output of time.Now() until the go program is restarted.

To reproduce, run a simple program that prints time.Now(), like the one below, and change the system timezone while it is running.
The output doesn't get updated with the new time/timezone until the program is restarted


import (
        "fmt"
        "time"
)

func main() {
        for {
                fmt.Println(time.Now().Format(time.RFC3339))
                time.Sleep(1 * time.Second)
        }
}

What did you expect to see?

The datetime should change to the new timezone

What did you see instead?

The datetime remains the same until the program is restarted

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions