老师帮我看看是这样写 的吗。谢谢。

来源: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回答

好帮手慕星星

2021-09-17

同学你好,月份输出是不对的

https://img.mukewang.com/climg/6143f70f0909e76d03360087.jpg

应该是九月,记得加1,因为月份从0开始。

另外建议优化分钟和秒数,两位数看着美观一些。参考:

https://img.mukewang.com/climg/6143f818095c154312850362.jpg

祝学习愉快!

0

0 学习 · 15276 问题

查看课程