You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Mayn\AppData\Local\go-build
set GOENV=C:\Users\Mayn\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Mayn\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Mayn\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:/Program Files/Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=D:\gamecomponents\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Mayn\AppData\Local\Temp\go-build4203366999=/tmp/go-build -gno-record-gcc-switches
What did you do?
func main() {
date := time.Date(2023, 12, 31, 0, 0, 0, 0, time.UTC)
lastMonth := date.AddDate(0, -1, 0)
fmt.Println("last year last month time:", lastMonth.Format("2006-01-02"))
now := time.Now().UTC()
nowLastMonth := now.AddDate(0, -1, 0)
fmt.Println("now last month time:", nowLastMonth.Format("2006-01-02"))
}
What did you see happen?
out: last year last month time: 2023-12-01
now last month time: 2024-12-01
What did you expect to see?
out: last year last month time: 2023-11-30
now last month time: 2024-11-30
I can achieve the effect myself through other methods, but I hope the standard package can fix this problem. I want to know if this problem has been fixed in other versions. If it has been fixed, please let me know the corresponding version.
The text was updated successfully, but these errors were encountered:
I think that for the operation of getting last month, I should give me the data of last month, right? Now that the method month is valid, the last month and this month must have the same current date? Then I think the month parameter is a bit confusing.
Go version
go1.22.4 windows/amd64
Output of
go env
in your module/workspace:What did you do?
func main() {
date := time.Date(2023, 12, 31, 0, 0, 0, 0, time.UTC)
lastMonth := date.AddDate(0, -1, 0)
fmt.Println("last year last month time:", lastMonth.Format("2006-01-02"))
now := time.Now().UTC()
nowLastMonth := now.AddDate(0, -1, 0)
fmt.Println("now last month time:", nowLastMonth.Format("2006-01-02"))
}
What did you see happen?
out: last year last month time: 2023-12-01
now last month time: 2024-12-01
What did you expect to see?
out: last year last month time: 2023-11-30
now last month time: 2024-11-30
I can achieve the effect myself through other methods, but I hope the standard package can fix this problem. I want to know if this problem has been fixed in other versions. If it has been fixed, please let me know the corresponding version.
The text was updated successfully, but these errors were encountered: