简体   繁体   English

如何找到以毫秒为单位的两个纪元时间之间的差异shell脚本

[英]How to find difference between two epoch time which is in milliseconds shell script

I want to calculate the difference between expiry time of token which is in epoch ms and current time in epoch ms.我想计算以纪元毫秒为单位的令牌到期时间与以纪元毫秒为单位的当前时间之间的差异。

Example expiry time of token is 1640237992708 which is 12th December 2021 and current time suppose is 1634108098242 which is 13th October 2021.令牌的示例到期时间为1640237992708 ,即 2021 年 12 月 12 日,当前时间假设为1634108098242 ,即 2021 年 10 月 13 日。

Basically I want to calculate the difference in days between the two timestamps.基本上我想计算两个时间戳之间的天数差异。

Like if the difference is less than 10 days and token will be expiring in 10 days, need to create a new token.就像如果差异小于 10 天并且令牌将在 10 天后到期,则需要创建一个新令牌。

Any idea how to get difference in days and than compare it with 10 days?知道如何获得天数差异而不是将其与 10 天进行比较吗?

Need to write in shell script.需要用shell脚本编写。

A naive approach would be to:一种天真的方法是:

a=1640237992708
b=1634108098242
diff="$((a-b))"
max_diff=$((1000 * 60 * 60 * 24 * 10))
if test "$diff" -gt "$max_diff"
then
  echo "Diff is higher than $max_diff"
fi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM