-1

I need to find the seconds long my token (jwt) is. Normally my token returns 2 properties that indicate the creation and the expiration date:

"iat": 1622583091
"exp": 1622584891

Now I need to find the difference in seconds between those two dates. The first thing I did is convert those dates to a readable format:

const iat = new Date (1622583091 * 1000); /* Tue Jun 01 2021 15:40:16 GMT-0600 (Central Standard Time) */
const iat = new Date (1622584891 * 1000); /* Tue Jun 01 2021 16:10:16 GMT-0600 (Central Standard Time) */

Worse now I can't think of how I can evaluate those dates and get the seconds of difference.

Josué Ayala
  • 285
  • 1
  • 12

1 Answers1

1

I found the way so simple, you just have to subtract the times iat and exp. This will return an integer:

const iat = 1622583091;
const exp = 1622584891;

let result = iat - exp;
console.log(Math.abs(result));

And here I already have my difference in seconds

DecPK
  • 24,537
  • 6
  • 26
  • 42
Josué Ayala
  • 285
  • 1
  • 12