Designed by 77
加载资源 ......
感谢 ♥ 作者
先不感谢了

js获取当前年月日周

使用setInterval每秒刷新一次:

const that = this
window.setInterval(function () { const addZero = function(num) { if (parseInt(num) < 10) { num = '0' + num } return num } const d = new Date() const year = d.getFullYear() // 获取年 const month = d.getMonth() + 1 // 获取月,从 Date 对象返回月份 (0 ~ 11),故在此处+1 const day = d.getDay() // 获取日 const days = d.getDate() // 获取日期 const hour = d.getHours() // 获取小时 const minute = d.getMinutes() // 获取分钟 const second = d.getSeconds() // 获取秒 const weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'] that.curDateTime = year + '-' + addZero(month) + '-' + addZero(days) + ' ' + addZero(hour) + ':' + addZero(minute) + ':' + addZero(second) that.curWeek = weeks[day] }, 1000)

 

posted @ 2023-07-12 15:39  yanggb  阅读(795)  评论(0编辑  收藏  举报