`

JS得到当前时间字符串

阅读更多
//得到当前时间字符串,格式为:YYYY-MM-DD HH:MM:SS  
function CurentTime()
{ 
	var now = new Date();
       
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日
       
    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
	var ss=now.getSeconds();			//秒
       
    var clock = year + "-";
       
    if(month < 10) clock += "0";       
    clock += month + "-";
       
    if(day < 10) clock += "0"; 
    clock += day + " ";
       
    if(hh < 10) clock += "0";
    clock += hh + ":";

    if (mm < 10) clock += '0'; 
    clock += mm+ ":";
		
    if (ss < 10) clock += '0'; 
	clock += ss;

    return(clock); 
}

 

分享到:
评论
1 楼 六年虚度 2016-06-01  
/* 防止backspace键后退网页 */
document.onkeydown = function(event) {
    if (event.keyCode == 8) {// backspace的keycode=8
        var type = document.activeElement.type;// 获取焦点类型
        if (type == "text" || type == "textarea" || type == "password"
                || type == "select") {// 判断焦点类型,无法输入的类型一律屏蔽
            if (document.activeElement.readOnly == false)// 如果不是只读,则执行本次backspace按键
                return true;
        }
        event.keyCode = 0;// 将本次按键设为0(即无按键)
        event.returnValue = false;
        return false;
    }
};

相关推荐

Global site tag (gtag.js) - Google Analytics