<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>localStorage.</title> <script type="text/javascript"> // About the localStorage expiration time setting var obj = new Object(); obj.a = a; obj.time = 3600; obj.date = new Date().getTime(); // Store to localStorage. localStorage.setItem('data', JSON.stringify(obj)); // get value var b = JSON.parse(localStorage.getItem('data')); var them = b.time; var data = b.date; if ((parseInt(time) + parseInt(data)) < new Date().getTime()) { // If it is less than that, it means that the data aging has expired and can be cleared. … localStorage.remove('data'); } else { // If it is larger than the description data, it is still valid console.log(b.a); } </script> </head> <body> </body> </html>