Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time error? #41270

Closed
owenzhou opened this issue Sep 8, 2020 · 2 comments
Closed

Time error? #41270

owenzhou opened this issue Sep 8, 2020 · 2 comments

Comments

@owenzhou
Copy link

owenzhou commented Sep 8, 2020

Time error?

package main

import(
	"fmt"
	"time"
)

func main(){
	timeLayout := "2006-01-02 15:04:05"

	t := "1990-08-17 13:14:15"

	t2 := "2000-08-17 13:14:15"

	loc, _ := time.LoadLocation("Asia/Shanghai")

	stamp, _ := time.ParseInLocation(timeLayout, t, loc)

	stamp2, _ := time.ParseInLocation(timeLayout, t2, loc)

	fmt.Println( "Datetime:", time.Unix(stamp.Unix(), 0) )

	fmt.Println( "Datetime:", time.Unix(stamp2.Unix(), 0) )
}

Result

  • Datetime: 1990-08-17 12:14:15 +0800 CST
    Datetime: 2000-08-17 13:14:15 +0800 CST

Why is there an hour difference?

@cespare
Copy link
Contributor

cespare commented Sep 8, 2020

The reason is that Daylight Savings Time was observed in China between 1986 and 1991.

I'm going to close this issue since it doesn't appear to be a bug in Go. Please use https://github.com/golang/go/wiki/Questions if you have further questions. Thanks.

@cespare cespare closed this as completed Sep 8, 2020
@owenzhou
Copy link
Author

owenzhou commented Sep 8, 2020

Oh, Thank you!

@golang golang locked and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants