丢代码
function getDate(dt) {
//var dt = new Date();
//获取年
var year = dt.getFullYear();
//获取月
var month = dt.getMonth() + 1;
//获取日
var day = dt.getDate();
//获取星期
//var week = dt.getDay();
//获取小时
var hours = dt.getHours();
//获取分
var min = dt.getMinutes();
//获取秒
var second = dt.getSeconds();
month = month < 10 ? "0" + month : month;
day = day < 10 ? "0" + day : day;
hours = hours < 10 ? "0" + hours : hours;
min = min < 10 ? "0" + min : min;
second = second < 10 ? "0" + second : second;
return year + "年" + month + "月" + day + "号" + hours + "时" + min + "分" + second + "秒";
}
//测试
console.log(getDate(new Date()));
结果