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

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

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanmaduan1848
    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.

    点赞 评论

相关推荐