I have a timestamp coming in, I wonder if there's a way to round it down to the start of a day in PST. For example, ts: 1305861602 corresponds to 2016-04-14, 21:10:27 -0700, but I want to round it to a timestamp that maps to 2016-04-14 00:00:00 -0700. I read through the time.Time doc but didn't find a way to do it.
时间到一天的时间
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
douqufan9148 2016-05-02 18:11关注The simple way to do this is to create new
Timeusing the previous one and only assigning the year month and day. It would look like this;rounded := time.Date(toRound.Year(), toRound.Month(), toRound.Day(), 0, 0, 0, 0, toRound.Location())here's a play example; https://play.golang.org/p/jnFuZxruKm
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报