JS中格式化时间
//格式化时间 function getDate(dt) { // var dt = new Date(); var year = dt.getFullYear();//获取年 var month = dt.getMonth();//获取月 var day = dt.getDay();//获取日 var hours = dt.getHours();//获取时 var minutes = dt.getMinutes();//获取分 var second = dt.getSeconds();//获取秒 month = month < 10 ? "0" + month : month; day = day < 10 ? "0" + day : day; hours = hours < 10 ? "0" + hours : hours; minutes = minutes < 10 ? "0" + minutes : minutes; second = second < 10 ? "0" + second : second; return year + "年" + month + "月" + day + "日" + hours + ":" + minutes + ":" + second } var dt = new Date(); document.write(getDate(dt)); //结果 2019年02月01日19:06:35