[Programming][localstorage] I want to store time in local storage & get it back

i working on reminder that get data from server & show them in webpage okay ? so i want to make the code work every hour but problem if i added setInterval & closed the webpage the time will start over & i tried to make it in localstorge something like:

var date = new Date();

var currentHour = date.getHours();

localStorage.setItem("currentHour", currentHour);

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

but its first time for me to deal with localstorage so that what i got from 2days thinking & trying so if anyone here can help me like “put me on the road” or something to know what i do


My JS code

var firebaseConfig = {
};
firebase.initializeApp(firebaseConfig);

var MedicalData = firebase.database().ref('Medical Data');
var dataRef = firebase.database().ref("Medical Data");
dataRef.on("value", gotData)

function gotData(data) {
var datalistings = document.querySelectorAll(".datalisting");
for (var i = 0; i < datalistings.length; i++) {
datalistings[i].remove();
}
var MedicalData = data.val();
var keys = Object.keys(MedicalData);
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
var decryptedName = CryptoJS.AES.decrypt(MedicalData[k].Name, "lol").toString(CryptoJS.enc.Utf8);
var decryptedMedicName = CryptoJS.AES.decrypt(MedicalData[k].MedicName, "lol").toString(CryptoJS.enc.Utf8);
var decryptedMedicTime = CryptoJS.AES.decrypt(MedicalData[k].MedicTime, "lol").toString(CryptoJS.enc.Utf8);
var decryptedNotes = CryptoJS.AES.decrypt(MedicalData[k].Notes, "lol").toString(CryptoJS.enc.Utf8);
var li = document.createElement('li');
li.innerHTML = "Name: " + decryptedName + " Medic Name: " + decryptedMedicName + " Medic Time: " + decryptedMedicTime + " Notes:" + decryptedNotes;
li.setAttribute("class", "datalisting");
document.getElementById("datalist").appendChild(li);
}

}
document.getElementById("encrypt").addEventListener("click", function (event) {
event.preventDefault()
var Name = document.getElementById("name");
var MedicName = document.getElementById("medic-name");
var MedicTime = document.getElementById("medic-time");
var Notes = document.getElementById("notes");
var encryptedName = CryptoJS.AES.encrypt(Name.value, "lol");
var encryptedMedicName = CryptoJS.AES.encrypt(MedicName.value, "lol");
var EncryptedMedicTime = CryptoJS.AES.encrypt(MedicTime.value, "lol");
var EncryptedNotes = CryptoJS.AES.encrypt(Notes.value, "lol");
document.getElementById("name").value = encryptedName;
document.getElementById("medic-name").value = encryptedMedicName;
document.getElementById("medic-time").value = EncryptedMedicTime;
document.getElementById("notes").value = EncryptedNotes;
var data = {
Name: document.getElementById("name").value,
MedicName: document.getElementById("medic-name").value,
MedicTime: document.getElementById("medic-time").value,
Notes: document.getElementById("notes").value
}
document.getElementById("name").disabled = true;
document.getElementById("medic-name").disabled = true;
document.getElementById("medic-time").disabled = true;
document.getElementById("notes").disabled = true;
MedicalData.push(data);
document.getElementById("name").disabled = false;
document.getElementById("medic-name").disabled = false;
document.getElementById("medic-time").disabled = false;
document.getElementById("notes").disabled = false;
alert("Data Sent!")
});
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
document.getElementById("email").style.display = "none";
document.getElementById("password").style.display = "none";
document.getElementById("login").style.display = "none";
document.getElementById("datalist").style.display = "block";
document.getElementById("addpeople").style.display = "block";
document.getElementById("logout").style.display = "block";
} else {
document.getElementById("email").style.display = "block";
document.getElementById("password").style.display = "block";
document.getElementById("login").style.display = "block";
document.getElementById("addpeople").style.display = "none";
document.getElementById("datalist").style.display = "none";
document.getElementById("logout").style.display = "none";
}
});
function login() {
var userEmail = document.getElementById("email").value;
var userPass = document.getElementById("password").value;
firebase.auth().signInWithEmailAndPassword(userEmail, userPass).catch(function (error) {
var errorCode = error.code;
var errorMessage = error.message;
alert("Error: " + errorMessage + ", " + "Error Code: " + errorCode);
});
}
function logout() {
firebase.auth().signOut();
}