Skip to content

time: i find some problems when using addDate to do date calculation #66374

@Gao-Vidor

Description

@Gao-Vidor

Go version

go version go1.20.5 darwin/amd64

go env :

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/Library/Caches/go-build"
GOENV="/Users/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"

What did i do?

package main

import (
"fmt"
"time"
)

func main() {
d := time.Date(2023, 1, 30, 23, 0, 0, 0, time.Local)
dd := d.AddDate(0, 1, 0)
fmt.Println(dd)
}

What did i see happen?

2023-03-02 23:00:00 +0000 UTC

What did i expect to see?

In my intuitive understanding, I believe the output should be 2023-02-28 (9) 23:00:00 +0000 UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions