Home > database >  How to find difference between two epoch time which is in milliseconds shell script
How to find difference between two epoch time which is in milliseconds shell script

Time:10-13

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.

CodePudding user response:

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
  • Related