dpd2349 2014-07-02 11:59
浏览 1928

Golang time.Now()始终为2009-11-10 23:00:00 +0000 UTC

im running Go version 1.3 on windows 7x64, after run the following code i always get 2009-11-10 23:00:00 +0000 UTC

package main

import (
    "fmt"
    "time"
)

func main() {
    fmt.Println(time.Now())
}

i know that go playgroud have this fixed time for one reason, but i don't understand why i get this date in my box

UPDATE: I realized this issue by upgrading the go version from 1.2.2 to 1.3

Trying to reproduce the issue, i realized this had been fixed after switching off and on computer next day.

I recommend to restart the computer after upgrading to 1.3

  • 写回答

3条回答 默认 最新

  • duanjing7298 2014-07-02 13:38
    关注

    I'm unable to reproduce your issue:

    C:\gopath\src\timenow>go version
    go version go1.3 windows/amd64
    C:\gopath\src\timenow>go env
    set GOARCH=amd64
    set GOBIN=C:\go\bin
    set GOCHAR=6
    set GOEXE=.exe
    set GOHOSTARCH=amd64
    set GOHOSTOS=windows
    set GOOS=windows
    set GOPATH=C:\gopath
    set GORACE=
    set GOROOT=C:\go
    set GOTOOLDIR=C:\go\pkg\tool\windows_amd64
    set CC=gcc
    set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
    set CXX=g++
    set CGO_ENABLED=1
    C:\gopath\src\timenow>type timenow.go
    package main
    
    import (
            "fmt"
            "time"
    )
    
    func main() {
            fmt.Println(time.Now())
    }
    C:\gopath\src\timenow>go run timenow.go
    2014-07-02 17:33:20.3270287 -0400 EDT
    C:\gopath\src\timenow>time
    The current time is: 17:33:23.60
    Enter the new time:
    C:\gopath\src\timenow>
    

    What output do you get when you run these commands?

    展开全部

    评论
  • douyan4958 2015-01-25 17:01
    关注

    That time is the fixed time used in the Go Tour as mentioned in the Go Tour limitations

    In the playground the time begins at 2009-11-10 23:00:00 UTC (determining the sigificance of this date is an exercise for the reader). This makes it easier to cache programs by giving them deterministic output.

    Are you sure you were not running code there? Possibly local version - you can download and run the tour.

    评论
  • doudun6928 2019-06-23 18:37
    关注

    This is the date and time of Go Langs birthday.

    They use this as the fixed time in the Go Tour, so perhaps you are running the tour.

    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部