I need to parse a datetime string that is generated by a pseudo random datetime generator that uses Unix() function. The generated datetime takes various date and time pairs between 2010 and 2017. Here's the problem, this version of the code works on both my computer and playground,
package main
import (
"fmt"
"time"
)
func main() {
a := time.Date(2016, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
kk := time.Unix(a, 0)
t, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", kk.String())
if err != nil {
panic(err)
}
fmt.Println(t)
}
But the version below works on playground and panics on my computer,
package main
import (
"fmt"
"time"
)
func main() {
a := time.Date(2018, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
kk := time.Unix(a, 0)
t, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", kk.String())
if err != nil {
panic(err)
}
fmt.Println(t)
}
Here's the error,
panic: parsing time "2017-12-31 03:00:00 +0300 +03" as "2006-01-02 15:04:05.999999999 -0700 MST": cannot parse "+03" as "MST"
The Go version I use is go1.8.3 darwin/amd64
.
Any ideas?