计算公式详解
结果是两个午夜时间戳之间的差值,再除以一天的毫秒数(86,400,000),并四舍五入到最接近的整天。四舍五入可以吸收夏令时切换带来的偏差,因此你得到的总是干净的整数天数。周数则只需把天数除以7即可。
$$\text{Days Until Spring} = \left\lfloor \frac{\text{Spring Equinox (Mar 20)} - \text{Start Date}}{86400000 \text{ ms/day}} \right\rceil$$
$$\begin{gathered} \text{Days} = \left\lfloor \frac{\text{Spring} - \text{Start Date}}{86400000} \right\rceil \\[1.5em] \text{where}\quad \left\{ \begin{aligned} \text{Spring} &= \text{March 20, } Y \\ Y &= \text{year of } \text{Start Date} \;(+1 \text{ if past}) \\ \text{Weeks} &= \text{Days} \div 7 \end{aligned} \right. \end{gathered}$$