0

How to convert string, "Fri Sep 22 2017 15:38:22 GMT+0630" in go.

layout := "Fri Sep 22 2017 15:38:22 GMT+0630"
    str := "Fri Sep 23 2017 15:38:22 GMT+0630"
    t, err := time.Parse(layout, str)
    if err != nil {
        WriteError(w, err)
        return
    }

Thanks, Alex

VincenzoC
  • 30,117
  • 12
  • 90
  • 112
Alex Aung
  • 2,637
  • 5
  • 34
  • 63

1 Answers1

1

These are predefined layouts for use in Time.Format and Time.Parse. The reference time used in the layouts is the specific time:

Mon Jan 2 15:04:05 MST 2006

which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as

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

So you need to put the date Mon Jan 2 15:04:05 MST 2006 into the format that you are expecting, which seems like it would be:

layout := "Mon Jan 02 2006 15:04:05 GMT-0700"

https://play.golang.org/p/I9dRT5JdOA

Community
  • 1
  • 1
dave
  • 62,300
  • 5
  • 72
  • 93