i'm trying to calculate between a date i put into localstorage and the current timestamp. I want to check how much minutes there is between the moment it was saved in localstorage and now. I cant figure out how to save the date in the localstorage as a propper date object tho!
The code is the following:
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
</head> 
<input type="text" id="text"> 
<button value="save" onClick="setStorage()" id="btn"> Save </button>
<script>
function setStorage(){
    var currentTime = new Date();
    var text = $("#text").val();
    var testobj = {'test' : 1, 'refresh' : currentTime};
    localStorage.setItem('storage', JSON.stringify(testobj));
}
// setinterval code is on different page
        setInterval(function() {
        var date2 = new Date();
        var retreived = localStorage.getItem('storage');
        var date1 = new Date(retreived['refresh'])
        console.log(date1);
        var parse = JSON.parse(retreived);
        console.log(date2 - date1);
        $(".label").text(localStorage.getItem('storage'));
     }, 1000);
</script>
The setinterval is on a different page. The outcome of the label is this:
{"test":1,"refresh":"2018-05-24T17:36:06.471Z"}
How could i compare that date with the current date, and check how much minutes there is between those 2 times?
Thanks!
 
    