英文:
Go time.Now() is always 2009-11-10 23:00:00 +0000 UTC
问题
我在Windows 7x64上运行Go版本1.3。运行以下代码后,我总是得到2009-11-10 23:00:00 +0000 UTC。
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now())
}
我知道Go Playground之所以有这个固定的时间,是有原因的,但我不明白为什么在我的电脑上会得到这个日期。
更新:
我通过将Go版本从1.2.2升级到1.3来解决了这个问题。
尝试重现这个问题后,我意识到在关机并在第二天重新启动电脑后,问题已经解决了。
我建议在升级到1.3后重新启动电脑。
英文:
I'm running Go version 1.3 on Windows 7x64. After I 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 has this fixed time for a reason, but I don't understand why I get this date in my box.
UPDATE:
I solved 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 the computer off and on the next day.
I recommend to restart the computer after upgrading to 1.3.
答案1
得分: 125
这是 Go 语言诞生的时间和日期。
他们在 Go Tour 中使用这个固定时间,所以也许你正在运行这个教程。
英文:
This is the time and date of Go Lang's birthday.
They use this as the fixed time in the Go Tour, so perhaps you are running the tour.
答案2
得分: 44
那个时间是Go Tour中使用的固定时间,正如在Go Tour限制中提到的。
在游乐场中,时间从2009年11月10日23:00:00 UTC开始(决定这个日期的重要性是给读者的一个练习)。这样做可以通过给程序提供确定性的输出来更容易地缓存程序。
你确定你没有在那里运行代码吗?
可能是本地版本-你可以下载并运行这个教程。
英文:
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.
答案3
得分: 6
当您运行这些命令时,您会得到以下输出:
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>
请问您运行这些命令时得到了什么输出?
英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论