I want to create a time.Time
for an exact point in time the following day (tomorrow). For now I would like to set the hour and minute.
This is the code I use at the moment:
now := time.Now()
tomorrow := time.Date(now.Year(), now.Month(), now.Day(), 15, 0, 0, 0, time.UTC).AddDate(0,0,1)
This will create a Date
for today with the exact time (hour and minute) I am looking for and then adds one day to that Date
. This works fine.
Example:
Imagine time.Now()
is 2009-11-10 23:00:00 +0000 UTC
.
The result of the following code would be: 2009-11-10 15:00:00 +0000 UTC
tomorrow := time.Date(now.Year(), now.Month(), now.Day(), 15, 0, 0, 0, time.UTC)
To this date I add one day using AddDate(0, 0, 1)
. The result is then the desired time the next day: 2009-11-11 15:00:00 +0000 UTC
.
See: https://play.golang.org/p/OKR9V1HN50x
Question:
Is there a shorter way to write this code?