duanbiyi7319 2015-07-08 12:22 采纳率: 100%
浏览 54
已采纳

如何在时间中将nsec设置为零时间键入的值

There's a time.Time value created from current time, is there any quick way to set its "nsec" field to zero? As this part in my case is not useful to map to a second level date time field in mysql.

  • 写回答

1条回答 默认 最新

  • douhuang2673 2015-07-08 12:26
    关注

    Use time.Truncate with time.Second:

    Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t unchanged.

    Playground: http://play.golang.org/p/go-IdYU18E.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?