You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using json.Marshal on a time value, I expected the a myTime.Location() to always be Local when the host timezone is set.
What did you see instead?
If my local time is set to GMT, I see UTC instead of Local.
using time.Parse() as shown in the example seems to work correctly, but when the value is marshaled to/from JSON the output is inconsistent between timezone.
The text was updated successfully, but these errors were encountered:
groob
added a commit
to kolide/fleet
that referenced
this issue
Nov 11, 2016
I tried time.Parse with RFC3339 time format, which makes the above clearer:
fmt.Println(time.Now().Format(time.RFC3339))
// Output in EST: 2016-11-12T11:12:37-05:00
// Output in PST: 2016-11-12T08:19:15-08:00
// Output in GMT: 2016-11-12T16:19:40Z
using time.Parse with 2016-11-12T16:19:40-00:00 prints Local correctly when in GMT.
This is a dupe of #17875; Local and UTC are the same if your timezone is GMT, so encoding/json is working as intended. We make no guarantees about which location object is attached to times, only that a time that is t.Equal is returned.
quentinmit
changed the title
encoding/json Marshalled time location inconsistent in GMT
encoding/json: Marshalled time location inconsistent in GMT
Nov 15, 2016
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7.3 (but tried tip as well)
What operating system and processor architecture are you using (
go env
)?What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/gFDhc-65Ft
What did you expect to see?
When using
json.Marshal
on a time value, I expected the amyTime.Location()
to always beLocal
when the host timezone is set.What did you see instead?
If my local time is set to GMT, I see
UTC
instead ofLocal
.using
time.Parse()
as shown in the example seems to work correctly, but when the value is marshaled to/from JSON the output is inconsistent between timezone.The text was updated successfully, but these errors were encountered: