Use time when the package
func (t Time) Add(d Duration) Time 我希望实现Add自定义时间
now := time.Now() now.Add(8*time.Second)
In the normal use, we are using the time and a literal integer multiplied time interval type.
I hope to do so
func SetOverdueTime (s int){ t := time.Now() t.Add(s*time.Second)
Austria has been an error, because the variable s and time.Second are two different types can not be multiplied. But can be directly multiplied by the literal is 8 * time.Second, the same value as a literal and the type of underlying multiply the result after denomination or type.
So Solution
func SetOverdueTime (s int){ t := time.Now() t.Add(time.Duration(s)*time.Second)
Do a cast on it. =. = Very low but still think we should remember this.
Here is the verification
a := 8 if 8*time.Second == time.Duration(a)*time.Second{ fmt.Printf("一样哒~") }