将自上周日午夜以来的秒数转换为日期和时间
Convert seconds since last sunday midnight to date and time
我知道自上周日午夜 UTC 以来已经过去了多少秒。是否可以从此信息中检索当前的 UTC 日期和时间?
我知道如何获取时间(取模),但是日期呢?由于闰日、闰年等原因,我无法理解它。
如果您知道 A
的日期,则只能使用 B = A + n
检索点 B
的日期。这个计算在任何方面都不是微不足道的,因为我们的日历是如此复杂。顺便说一句:last sunday
只是一个相对日期。
使用 BusyBox,您可以尝试使用 date
能够进行计算的工具,例如
date +"%s" --date="last sunday"
给你。例如(n = number of seconds passed from last sunday
)
A_s=$(date +"%s" --date="last sunday")
let 'B_s=A_s + n'
date -u --date="@""${B_s}"
从您的代码中作为 shell 脚本调用。
我知道自上周日午夜 UTC 以来已经过去了多少秒。是否可以从此信息中检索当前的 UTC 日期和时间?
我知道如何获取时间(取模),但是日期呢?由于闰日、闰年等原因,我无法理解它。
如果您知道 A
的日期,则只能使用 B = A + n
检索点 B
的日期。这个计算在任何方面都不是微不足道的,因为我们的日历是如此复杂。顺便说一句:last sunday
只是一个相对日期。
使用 BusyBox,您可以尝试使用 date
能够进行计算的工具,例如
date +"%s" --date="last sunday"
给你。例如(n = number of seconds passed from last sunday
)
A_s=$(date +"%s" --date="last sunday")
let 'B_s=A_s + n'
date -u --date="@""${B_s}"
从您的代码中作为 shell 脚本调用。