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

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

问题描述:

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

如何在Go中的 time.Time code>结构中获取昨天的日期? p> div>

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.