Hi Ian,
Thanks for the response. When marshalling or converting to string, it seems like go does add a local time zone (code below). I do not see the Local field on the Time struct.
The only way I have found to create UTC times is to manually set this with time structs I create is by calling:
location, _ := time.LoadLocation("UTC")
time := time.Now().In(location)
return &time
This approach only works when I create the time struct. When it comes from a 3rd party library (e.g., db driver), I have no control over setting this unless I manually add code to each struct after it has been retrieved, and this is highly undesirable.
Thanks,
-Ryan
Here is some test code:
package main
import (
"fmt"
"time"
"encoding/json"
)
type testJson struct { TheTime time.Time `json:"theTime"` }
func main() {
now := time.Now()
fmt.Println(now)
test := &testJson{ TheTime: now }
if raw, err := json.Marshal(test); err != nil { fmt.Println(err)
} else { fmt.Println(string(raw)) }
}
The output for this code is:
2014-07-19 16:55:38.328988572 -0400 EDT
{"theTime":"2014-07-19T16:55:38.328988572-04:00"}