Is this the best way of getting tomorrow 09:00?

Viewed 131

I want to get a datetime object for tomorrow morning 09:00 in Go. My current take is this:

now := time.Now()
tomorrowMorning := time.Date(now.Year(), now.Month(), now.Day(), 9, 0, 0, 0, time.UTC).AddDate(0, 0, 1))

It seems oddly verbose though. Isn't there a simpler way of doing this?

1 Answers

Simplify by adding 1 to the day directly.

now := time.Now()
tomorrowMorning := time.Date(now.Year(), now.Month(), now.Day() + 1, 9, 0, 0, 0, time.UTC)

Run it on the playground.

The time.Date function normalizes the day.

Related