js显示当前时间

效果:

js显示当前时间

html:

<div class="time">
                        <ul>
                                <li>
                                        {{ dateObj.date }}
                                </li>
                                <li>
                                        {{ dateObj.week }}
                                </li>
                        </ul>
</div>

js:

export default {
        data() {
                return {
                        dateObj: {
                                year:"",
                                month:"",
                                date: "",
                                week: "",
                                // timer: null,
                        },
                };
        },
        methods: {
                getDateTime() {
                        const ddd = this;
                        function getDateFun() {
                                let d = new Date();
                                let year = d.getFullYear();
                                let month = d.getMonth();
                                let date = d.getDate();
                                let day = d.getDay();
                                let weekday = [
                                        "星期日",
                                        "星期一",
                                        "星期二",
                                        "星期三",
                                        "星期四",
                                        "星期五",
                                        "星期六",
                                ];
                                ddd.dateObj.date = year + ‘-‘ + month + ‘-‘ + date;
                                ddd.dateObj.week = weekday[day];
                        }
                        getDateFun();
                },
        },
        mounted() {
                this.getDateTime();
        },
};

 

js显示当前时间

上一篇:linux 之 bash: telnet: command not found...报错


下一篇:html当中如何引用js文件