JS获取当前时间转为年月日时分秒字符串格式

 		var now = new Date();
        var yy = now.getFullYear(); //年
        var mm = now.getMonth() + 1; //月
        var dd = now.getDate(); //日
        var hh = now.getHours(); //时
        var ii = now.getMinutes(); //分
        var ss = now.getSeconds(); //秒
        var time = yy + "-";
        if (mm < 10) time += "0";
        time += mm + "-";
        if (dd < 10) time += "0";
        time += dd + " ";
        if (hh < 10) time += "0";
        time += hh + ":";
        if (ii < 10) time += '0';
        time += ii + ":";
        if (ss < 10) time += '0';
        time += ss;
        
        console.log(time); //获取当前日期 2019-04-17 10:27:27
展开阅读全文

没有更多推荐了,返回首页