这是我的代码
package main
import (
"fmt"
"time"
)
func main() {
tz := "America/New_York"
loc, err := time.LoadLocation(tz)
if err != nil {
fmt.Println(err)
}
fmt.Println(time.Now().In(loc))
}
它应该得到像The Go Playground
这样的结果2009-11-10 18:00:00 -0500 EST
奇怪的是,当我尝试在我的服务器上运行时,它打印出UTC
时间而不是EST
2017-11-22 14:53:16.94672706 +0000 UTC
某些环境
go version go1.8.3 linux/amd64
Linux version 3.10.0-514.21.2.el7.x86_64 (mockbuild@x86-037.build.eng.bos.redhat.com) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Sun May 28 17:08:21 EDT 2017
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build674699918=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
答案 0 :(得分:0)
事实证明系统tzdata
包已过期
sudo yum update tzdata
此命令修复了问题,如@Adrian
所示