0

I am trying to cast a value to a struct which has a type of time.Time.

The value is:

t := time.Now()
format := "2006-01-02 15:04:05"

Then I am trying to put this into the struct:

response.SetAppData[0].LiveDate = time.Parse(format, t.String())

However I get the error of:

controllers/apps.go:1085: multiple-value time.Parse() in single-value context

I am not sure what I am doing wrong.

Thanks

Elliot Reeve
  • 901
  • 4
  • 21
  • 39

1 Answers1

2

It means that time.Parse returns two results time.Time and error values. You are assigning only to one variable.

You should do that:

response.SetAppData[0].LiveDate, err = time.Parse(format, t.String())
if err != nil {
    // error handling here
}
Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
  • So this works, but the response I get is not what I am expecting. I just want to cast the value e.g. 2016-04-04 13:33:00 into the Struct. – Elliot Reeve Apr 04 '16 at 14:06