var oDate = new Date(); var time = toDate(oDate.getFullYear()) + "年" + toDate(oDate.getMonth() + 1) + "月" + toDate(oDate.getDate()) + "日" + toDate(oDate.getHours()) + "时" + toDate(oDate.getMinutes()) + "分" + toDate(oDate.getSeconds() + "秒:"); function toDate(len) //这个方法用于判断是否是两位数 不是的话前面补个0 { if(len < 10) { return ‘0‘ + len; }else{ return ‘ ‘ + len; } }