代码来自此页面:https: //github.com/reddit/reddit/blob/master/r2/r2/lib/db/_sorts.pyx
这是代码片段:
cpdef double epoch_seconds(date):
"""Returns the number of seconds from the epoch to date. Should
match the number returned by the equivalent function in
postgres."""
td = date - epoch
return td.days * 86400 + td.seconds + (float(td.microseconds) / 1000000)
Run Code Online (Sandbox Code Playgroud)
我觉得td.days * 86400应该等于td.seconds还有(float(td.microseconds) / 1000000),我想知道为什么他们不只是让td.seconds乘以3?
你的假设是错误的,这就是为什么这种接缝很奇怪.td.days包含自为你正确地估计了划时代的天数,但td.seconds并td.microseconds包含自一天开始,自第二的分别开始的微秒数的秒数.因此,返回值变为自纪元以来的秒数,微秒作为逗号之后的部分.