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.
Enter formula =A1+TIME(0,20,0) into the Formula Bar, and then press the Ctrl + Enter key simultaneously. You can see each cell time is added with 20 minutes increments and listed in selected range immediately.
To add time, you add the hours together, then you add the minutes together. Because there are only 60 minutes in an hour, you cannot have a time whose minute value is greater than 60. In this case, subtract 60 minutes and add 1 more to the hour.
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))
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With