简体   繁体   中英

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.

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.

Any idea how to get difference in days and than compare it with 10 days?

Need to write in shell script.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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