'Adding hours, minutes, seconds to current time

How do I add hours, minutes, and seconds (defined as ints) to the current time, similar to AddDate?

timein := time.Now().Local().AddDate(Hours, Mins, Sec)

but with hours, minutes, and seconds.



Solution 1:[1]

I guess what you are looking for is

timein := time.Now().Local().Add(time.Hour * time.Duration(Hours) +
                                 time.Minute * time.Duration(Mins) +
                                 time.Second * time.Duration(Sec))

Solution 2:[2]

This answer is outdated. Please see this answer.


AddDate takes (and adds) year, month, day as parameters, not hour, minute, second.

From https://golang.org/pkg/time/#Time.AddDate:

func (t Time) AddDate(years int, months int, days int) Time

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark Harrison
Solution 2