vue.js 如何保存本地存储时间戳并获取差异?

owfi6suc  于 2022-12-23  发布在  Vue.js
关注(0)|答案(2)|浏览(178)

我想给localstorage设置一个时间戳。我设置的时间戳应该从当前时间中减去。我想做的是倒计时

funcion setLocalStorage(){
           localStorage.setItem("countDown", new Date().toString());
                         }

funcion getLocalStorage(){
           return localStorage.getItem("countDown");
                         }

let diff = new Date() - getLocalStorage()
dzhpxtsq

dzhpxtsq1#

第一个月
那么
let diff = new Date().getTime() - Number(getLocalStorage())

watbbzwu

watbbzwu2#

function setLocalStorage() {
    localStorage.setItem("countDown", Date.now());
}

function getLocalStorage() {
    return localStorage.getItem("countDown");
}

let diff = Date.now() - getLocalStorage();

相关问题