On Mon, Feb 11, 2019 at 10:53 AM <[email protected]> wrote:
>
> Hi all, please could you help me with a simple problem?
>
> I have some parsing code like this: https://play.golang.org/p/6bVyWg4FCVN
>
> It writes
>
> 20190211T103847+0000
> <nil>
> 2019-02-11 10:38:47 +0000 UTC
>
>
> on the server.
>
> When I put the code into test,
>
> package tcx_test
>
> import (
> "fmt"
> "testing"
> "time"
> )
>
> func TestTemp(t *testing.T) {
> date := "20190211T103847-0000"
> parsed, err := time.Parse("20060102T150405-0700", date)
> fmt.Println(date)
> fmt.Println(err)
> fmt.Println(parsed)
> }
>
> it outputs
>
> >go test
> 20190211T103847-0000
> <nil>
> 2019-02-11 10:38:47 +0000 +0000
> PASS
> ok tc/tcx 0.048s
>
> Why there is UTC in the first output, but +0000 in the second one?
It depends on the timezone information available on the system and on
the system's local time zone. If the system's local time zone is UTC,
that will be used. Otherwise, the time will use an unnamed timezone
at offset +0000. That winds up with the difference that you see. See
the docs for time.Parse:
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.
Ian
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.