I want to set localstorage' a timestamp. The time timestamp I set should be subtracted from the current time. What i want to do is a countdown
funcion setLocalStorage(){
localStorage.setItem("countDown", new Date().toString());
}
funcion getLocalStorage(){
return localStorage.getItem("countDown");
}
let diff = new Date() - getLocalStorage()
CodePudding user response:
localStorage.setItem("countDown", new Date().getTime());
then
let diff = new Date().getTime() - Number(getLocalStorage())
CodePudding user response:
function setLocalStorage() {
localStorage.setItem("countDown", Date.now());
}
function getLocalStorage() {
return localStorage.getItem("countDown");
}
let diff = Date.now() - getLocalStorage();