js-获取今天零点时间戳

获取 今天零点 时间戳

直接获取日期再次计算时间戳

    function fun00(){
        let today = new Date();
        return new Date(today.toDateString()).getTime();
    }

    function fun01(){
        let today = new Date();
        return new Date(today.getFullYear()+'/'+today.getMonth()+1+'/'+today.getDate()).getTime();
    }

减去今天已过去的时间

    function fun10(){
        let today = new Date();
        return today.getTime() - today.getHours() * 60 * 60 * 1000 - today.getMinutes() * 60 * 1000 - today.getSeconds() * 1000 - today.getMilliseconds();
    }

通过时间戳取模(需要矫正时区)

    function fun20{
        let tsp = Date.now();
        return tsp-tsp%8640000-new Date().getTimezoneOffset()*6000;
    }

通过设置当前Date,获取时间戳

    function fun30{
        let today = new Date();
        today.setHours(0,0,0,0);
        return today.getTime();
    }

你可能感兴趣的:(JS,javascript,vue.js,开发语言)