function chkTime(num){ return num<10?"0"+num:num; } Date.prototype.
function chkTime(num){
??? ??? ??? return num<10?"0"+num:num;
}
Date.prototype.format = function(date , dformat){
??? ??? ??? //Y:年 m:月 d:日 H:时 i:分 s:秒
??? ??? ??? var year = date.getFullYear();
??? ??? ??? var month = chkTime(date.getMonth()+1);
??? ??? ??? var day = chkTime(date.getDate());
??? ??? ??? var hours = chkTime(date.getHours());
??? ??? ??? var minutes = chkTime(date.getMinutes());
??? ??? ??? var seconds = chkTime(date.getSeconds());
??? ??? ??? return dformat.replace("Y",year).replace("m",month).replace("d",day)
.replace("H",hours).replace("i",minutes).replace("s",seconds);
??? ??? ????
??? ??? }
?
使用方法:
?
var date = new Date();
??? ???? alert(date.format(date, "Y-m-d H:i:s"));