First of all: You're silently ignoring the error this is returned as second return value of time.Parse
. I'd suggest handling the error appropriately, instead.
Secondly, let's have a look at the documentation of time.Parse
:
Parse
parses a formatted string and returns the time value it represents. The layout defines the format by showing how the reference time, defined to be Mon Jan 2 15:04:05 -0700 MST 2006
would be interpreted if it were the value; it serves as an example of the input format. The same interpretation will then be made to the input string.
The time.Parse
function expects its layout
parameter to represent a fixed example date. So, in order to parse the date Sun, 03 Jan 2016 10:00:07 CET
, the appropriate example layout string should be Mon, 02 Jan 2006 15:04:05 MST
:
layout := "Mon, 02 Jan 2006 15:04:05 MST"
t, err := time.Parse(layout, "Sun, 03 Jan 2016 10:00:07 CET")
if err != nil {
// handle the error somehow!
}
fmt.Println(t)