How to create a time duration in a for loop - (mismatched types int and time.Duration)

Viewed 3611

I have a loop where I start by a time.Time and I what to add a minute.

 for idx := range keys {
    var a = idx * time.Minute
    var t = tInit.Add(time.Minute * a)
    fmt.Println(t, idx)


 }

Here is my error

invalid operation: idx * time.Minute (mismatched types int and time.Duration)
1 Answers

The operands to numeric operations must have the same type. Convert the int value idx to a time.Duration: var a = time.Duration(idx) * time.Minute

Related