老师帮我看看是这样写 的吗。谢谢。
来源:7-14 编程练习
慕斯卡2474635
2021-09-16 22:57:21
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>改变日期格式</title>
</head>
<body>
<script>
//补充代码
var newDate = new Date();
var arrDay = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
function fun() {
var date = '今天是' + newDate.getFullYear() + '年' + newDate.getMonth() + '月' + newDate.getDate() + '日' + arrDay[newDate.getDay()] + '<br>' + newDate.getHours() + ':' + newDate.getMinutes() + ':' + newDate.getSeconds();
return date;
}
document.write(fun());
</script>
</body>
</html>
1回答
同学你好,月份输出是不对的

应该是九月,记得加1,因为月份从0开始。
另外建议优化分钟和秒数,两位数看着美观一些。参考:

祝学习愉快!
相似问题