Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: since or time.Now().Sub(t) returns wrong when t is start date of the calender #61396

Closed
ErfanMomeniii opened this issue Jul 17, 2023 · 1 comment

Comments

@ErfanMomeniii
Copy link

What version of Go are you using (go version)?

$ go version
1.20.3

What did you expect to see?

I wanted to calculate the number of seconds that have passed since the start of the calendar.

fmt.Println(time.Now().UTC().Sub(time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)))

it returned the wrong answer.

2562047h47m16.854775807s

from the number of hours, we can calculate 292 years but we are in 2023 now.

@ErfanMomeniii ErfanMomeniii changed the title time: since or time.Now().Sub(t) returns wrong when t is time.date of start of the calender time: since or time.Now().Sub(t) returns wrong when t is date of start of the calender Jul 17, 2023
@ErfanMomeniii ErfanMomeniii changed the title time: since or time.Now().Sub(t) returns wrong when t is date of start of the calender time: since or time.Now().Sub(t) returns wrong when t is start date of the calender Jul 17, 2023
@seankhliao
Copy link
Member

it's unfortunate but int64 can only represent so much time at nanosecond resolution.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants