-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Milestone
Description
jb@syno:~ $ cat test.go
package main
import (
"fmt"
"time"
)
func main() {
t, _ := time.Parse("2006-01-02 15:04:05 -0700", "2015-07-13 12:13:14 +0000")
fmt.Println(t)
t, _ = time.Parse("2006-01-02 15:04:05", "2015-07-13 12:13:14")
fmt.Println(t)
}
jb@syno:~ $ go version
go version devel +b6ead9f Tue Jul 7 21:53:11 2015 +0000 darwin/amd64
jb@syno:~ $ go run test.go
2015-07-13 12:13:14 +0000 +0000
2015-07-13 12:13:14 +0000 UTC
jb@syno:~ $
I guess this is due to
When parsing a time with a zone offset like -0700, if the offset corresponds to a time zone used by the current location (Local), then Parse uses that location and zone in the returned time. Otherwise it records the time as being in a fabricated location with time fixed at the given zone offset.
in Parse...? However, perhaps the fabricated location for +0000 should be UTC? It also seems system specific, as http://play.golang.org/p/NYpETX_L9a actually prints UTC in both cases.
(Dates returned from database/sql, at least with the github.com/lib/pq driver, suffer from this so it's not only synthetic.)