dongwen6743 2016-06-08 08:35
浏览 2253
已采纳

如何在golang中获取昨天的日期?

How do I get yesterday's date in the time.Time struct in Go?

  • 写回答

1条回答 默认 最新

  • duanmaduan1848 2016-06-08 08:45
    关注

    Here's one way with AddDate:

    time.Now().AddDate(0, 0, -1)
    

    EDIT

    The original answer also had a time.Add suggestion:

    fmt.Printf("Yesterday: %v
    ", time.Now().Add(-24*time.Hour))
    

    See Vatine's comment for reasons to prefer AddDate.

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

报告相同问题?