Skip to content

日期时间

获取当前日期时间

date

计算时间差

start_time=$(date +%s)

sleep 1

end_time=$(date +%s)

diff_time=$((end_time-start_time))

echo "$diff_time秒"

计算最近的 30 分钟(1800 秒)对齐的时间

interval=1800

unix_seconds=$(date +%s)

aligned_seconds=$(( (unix_seconds / interval) * interval ))

aligned_date=$(date -d "@$aligned_seconds")

echo $aligned_date

联系 math@baima.site