Consider the following code:
package main
import (
"time"
"fmt"
)
const (
format = "2006 01 02 15:04 MST"
date = "2018 08 01 12:00 EDT"
)
func main() {
aloc, _ := time.LoadLocation("America/New_York")
eloc, _ := time.LoadLocation("Europe/Berlin")
tn, _ := time.Parse(format, date)
tl, _ := time.ParseInLocation(format, date, aloc)
fmt.Println(tn)
fmt.Println(tn.In(eloc))
fmt.Println(tl)
fmt.Println(tl.In(eloc))
}
You can also try it on the Go Playground .
When I run it, I get this result (both on my own system and through the Playground):
2018-08-01 12:00:00 +0000 EDT
2018-08-01 14:00:00 +0200 CEST
2018-08-01 12:00:00 -0400 EDT
2018-08-01 18:00:00 +0200 CEST
I expected the first and third lines to be the same, and the second and fourth to be the same.
It seems to me that the Go time library does not parse the time zone identifier "EDT" that I wrote on the date line, despite the fact that it is part of the format.
My own system (Fedora 26) also recognizes EST / EDT as a time zone:
$ TZ='America/New_York' date 080112002018
Wed 1 Aug 12:00:00 EDT 2018
, , ParseInLocation(), , . "EDT" "America/New_York".
- ?