특정 날짜에서 3달 전 혹은 2주 전 등의 날짜를 구하고 싶다면 time 패키지에 AddDate() 함수를 이용하면 됩니다.
func threeMonthAgo() {
t := time.Now()
t2 := t.AddDate(0, -3, 0)
fmt.Printf("now : %+v\n", t)
fmt.Printf("threeMonthAgo: %+v\n", t2)
}
now : 2022-07-15 00:16:43.869676 +0900 KST m=+0.000060240
threeMonthAgo: 2022-04-15 00:16:43.869676 +0900 KST
[Golang]문자열 양쪽 여백 혹은 문자(들) 삭제(Trim)하기 (0) | 2022.07.15 |
---|---|
[Golang]time.Time 구조체 기본값은 무엇일까요 (0) | 2022.07.08 |
[Golang]싱글톤(singleton) 패턴 구현하기 (0) | 2022.07.01 |
[Golang] "net/http: TLS handshake timeout" error (0) | 2022.07.01 |
[Golang]UUID 만들기 (0) | 2022.06.24 |