time.Time Round to Day

前端 未结 4 1118
野趣味
野趣味 2021-02-01 13:32

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,

4条回答
  •  情书的邮戳
    2021-02-01 14:01

    You can simply use duration 24 * time.Hour to truncate time.

    t := time.Date(2015, 4, 2, 0, 15, 30, 918273645, time.UTC)
    d := 24 * time.Hour
    t.Truncate(d)
    

    https://play.golang.org/p/BTz7wjLTWX

提交回复
热议问题