英文:
in golang go/src/time.go, why daysPer100Years = 365*100 + 24?
问题
我正在阅读package time
的Golang源代码,并且遇到了一些常量,如下所示:
// 文件路径:/usr/local/go/src/time/time.go
const (
secondsPerMinute = 60
secondsPerHour = 60 * secondsPerMinute
secondsPerDay = 24 * secondsPerHour
secondsPerWeek = 7 * secondsPerDay
daysPer400Years = 365*400 + 97
daysPer100Years = 365*100 + 24
daysPer4Years = 365*4 + 1
)
我想知道为什么是这样的:
daysPer400Years = 365*400 + 97
daysPer100Years = 365*100 + 24
而不是这样的:
daysPer400Years = 365*400 + 100
daysPer100Years = 365*100 + 25
英文:
I'm reading golang source code of package time
And I got some constants like:
// file: /usr/local/go/src/time/time.go
const (
secondsPerMinute = 60
secondsPerHour = 60 * secondsPerMinute
secondsPerDay = 24 * secondsPerHour
secondsPerWeek = 7 * secondsPerDay
daysPer400Years = 365*400 + 97
daysPer100Years = 365*100 + 24
daysPer4Years = 365*4 + 1
)
I'm wondering why
daysPer400Years = 365*400 + 97
daysPer100Years = 365*100 + 24
but not
daysPer400Years = 365*400 + 100
daysPer100Years = 365*100 + 25
答案1
得分: 1
当我输入这个问题时,我自己得到了答案 😊 ----
通常,我们称年份X为闰年,如果X可以被4整除。然而,如果年份X可以被100整除但不能被400整除,我们称X不是闰年。
这意味着,每100年至少有24个闰年。在这100年中,有一年必须可以被100整除,但可能不能被400整除,这种情况发生的概率是3/4。换句话说,每100年,24个闰年的概率为75%,25个闰年的概率为25%。这就是为什么
daysPer100Years = 365*100 + 24
每400年,必定有3个年份可以被100整除但不能被400整除。
这就是为什么
daysPer400Years = 365*400 + 97
//即:daysPer400Years = 365*400 + (25 * 4 - 3)
//或者:daysPer400Years = 365*400 + (24 * 4 + 1)
英文:
When I'm typing this question, I got the answer myself 😂 ----
Usually we call a year X is a leap year if X is divisible by 4. While the year X is divisible by 100 but not divisible by 400, we say X is not a leap year.
That means, every 100 years, there are at least 24 leap years. Among the 100 years, there is a year which must be divisible by 100, but may not be divisible by 400, this phenomenon occurs by the probability of 3/4. In other words, every 100 years, the probability of 24 leap years is 75%, and 25% for 25 leap years. That's why
daysPer100Years = 365*100 + 24
Every 400 years, there must be 3 years which can be divisible by 100 but not divisible by 400.
That's why
daysPer400Years = 365*400 + 97
//that is : daysPer400Years = 365*400 + (25 * 4 - 3)
// or : daysPer400Years = 365*400 + (24 * 4 + 1)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论