0

I have working jwt token in springboot app in backend then I'm used that token react front end app. now I want to backend token expiry time set and stored console...

const decodedToken = jwt_decode(token); 
localStorage.setItem("time", decodedToken.exp); 

console.log(localStorage.getItem("time")) 

Using the above code to retrieve the expiry time in seconds. But it return this code 1661342806.

  • What do you mean you want the expiry time in seconds? How many seconds until your token expires? Your token expired August 24, 2022 12:06:46 PM. – C. Helling Aug 25 '22 at 17:32
  • Does this answer your question? [What format is the exp (Expiration Time) claim in a JWT](https://stackoverflow.com/questions/39926104/what-format-is-the-exp-expiration-time-claim-in-a-jwt) – jps Aug 25 '22 at 17:32
  • I need get time only. Not date and month. –  Aug 25 '22 at 17:46

1 Answers1

0

The number you are returning is the number of seconds since January 1, 1970 12:00:00 AM GMT. To get the time portion (as you indicated in your comments), you'd first need to convert it to a date, and then just take the time portion of that date.

For example:

var unixTimestamp = localStorage.getItem("time"); // 1661342806 
var d = new Date(unixTimestamp * 1000).toLocaleTimeString();
C. Helling
  • 1,394
  • 6
  • 20
  • 34