parsing - time.Parse behaviour -


in go, while trying convert string time.time, using time package's parse method doesn't return expected result. seems problem timezone. want change iso 8601 combined date , time in utc.

package main  import (     "fmt"     "time" )  func main() {     const longform = "2013-05-13t18:41:34.848z"     //even not working     //const longform = "2013-05-13 18:41:34.848 -0700 pdt"     t, _ := time.parse(longform, "2013-05-13 18:41:34.848 -0700 pdt")     fmt.println(t)     //outputs 0001-01-01 00:00:00 +0000 utc } 

thanks in advance!

your format string longform not correct. you know if have not been ignoring returned error. quoting docs:

these predefined layouts use in time.format , time.parse. reference time used in layouts is:

mon jan 2 15:04:05 mst 2006 

which unix time 1136239445. since mst gmt-0700, reference time can thought of as

01/02 03:04:05pm '06 -0700 

to define own format, write down reference time formatted way; see values of constants ansic, stampmicro or kitchen examples.

package main  import (         "fmt"         "log"         "time" )  func main() {         const longform = "2006-01-02 15:04:05 -0700"         t, err := time.parse(longform, "2013-05-13 18:41:34.848 -0700")         if err != nil {                 log.fatal(err)         }         fmt.println(t) } 

playground


output:

2013-05-13 01:41:34.848 +0000 utc 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -