My code to set local storage like this :
var now = new Date();
now.setHours(now.getHours() + 1);
var cacheData = {data: data, expired: now}
localStorage.setItem('storedData', JSON.stringify(cacheData))
My code to check expired or no like this :
var object = JSON.parse(localStorage.getItem("storedData")),
expired = object.expired,
now = new Date()
if(now > expired) {
console.log('cache dihapus')
localStorage.removeItem("storedData");
}
After 1 hour, I run the script, but the local storage not remodev
Why it not removed?
The result of console.log(now) and console.log(expired) like this :
Wed Aug 09 2017 17:41:13 GMT+0700 (Russia TZ 6 Standard Time)
2017-08-09T10:29:21.933Z
Seems the format different. Maybe its a problem there