function getDate(time) { //获取年份 var year = time.getFullYear(); //获取月份 var month = time.getMonth() + 1; //获取日期 var day = time.getDate(); //获取时间小时 var hour = time.getHours(); //获取分钟 var minutes = time.getMinutes(); //获取秒 var seconds = time.getSeconds(); //获取星期 var week = time.getDay(); //日期小时分钟秒小于10,前面加0 month = month < 10 ? "0" + month : month; day = day < 10 ? "0" + day : day; hour = hour < 10 ? "0" + hour : hour; seconds = seconds < 10 ? "0" + seconds : seconds; return "当前是" + year + "年" + "month" + "月" + day + "号," + hour + ":" + minutes + ":" + seconds + "分," + week; } console.log(getDate(new Date()));
为什么getmonth();月份显示不出来?显示的是变量名month,其他的年份,小时,分钟,秒都可以正常显示,不知道哪里出错了,求指教~谢谢 cry
pardon110