这是获得明天 09:00 的最佳方式吗?

kra*_*r65 3 time datetime go

我想在 Go 中获取明天早上 09:00 的日期时间对象。我目前的看法是这样的:

now := time.Now()
tomorrowMorning := time.Date(now.Year(), now.Month(), now.Day(), 9, 0, 0, 0, time.UTC).AddDate(0, 0, 1))
Run Code Online (Sandbox Code Playgroud)

不过,这似乎有点冗长。没有更简单的方法来做到这一点吗?

Cer*_*món 5

直接在天上加 1 来简化。

now := time.Now()
tomorrowMorning := time.Date(now.Year(), now.Month(), now.Day() + 1, 9, 0, 0, 0, time.UTC)
Run Code Online (Sandbox Code Playgroud)

在操场上运行它。

该time.Date功能使一天正常化。