获取当前时间模块

 

         function CurentTime(){ 
            var now = new Date();       
            var year = now.getFullYear();       //
            var month = now.getMonth() + 1;     //
            var day = now.getDate();            //
            var h = now.getHours();            //
            var m = now.getMinutes();          //
            var s = now.getSeconds();           //
            var clock = year + "-";       
            if(month < 10)
                clock += "0";      
            clock += month + "-";      
            if(day < 10)
                clock += "0";           
            clock += day + " ";        
            if(h < 10)
                clock += "0";           
            clock += h + ":";
            if (m < 10) clock += '0'; 
            clock += m + ":";        
            if (s < 10) clock += '0'; 
            clock += s; 
            return(clock); 
    }
    setTimeout(()=>{
        console.log(CurentTime())
    },1000)

 

posted @ 2021-11-16 12:51  keyeking  阅读(28)  评论(0编辑  收藏  举报