var nowDate = new Date();var year = nowDate.getFullYear(); var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1; var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate(); var hours = nowDate.getHours()<10?"0" + nowDate.getHours():nowDate.getHours(); var minutes = nowDate.getMinutes()<10?"0" + nowDate.getMinutes():nowDate.getMinutes(); var seconds = nowDate.getSeconds()<10?"0" + nowDate.getSeconds():nowDate.getSeconds(); var dateStr = year + "-" + month + "-" + day+ " " + hours+ ":" + minutes+ ":" + seconds; console.log(dateStr);
这是结果
我要转html5和js,哎,其实还挺喜欢写后端的,但是希望自己转变一下,加油吧