0 获取本周(周一~~周日)
getweekDates () {let new_Date &#61; new Date()let timesStamp &#61; new_Date.getTime()let currenDay &#61; new_Date.getDay()let dates &#61; []for (var i &#61; 0; i <7; i&#43;&#43;) {let time &#61; new Date(timesStamp &#43; 24 * 60 * 60 * 1000 * (i - (currenDay &#43; 6) % 7)).toLocaleDateString().replace(/[年月]/g, &#39;-&#39;).replace(/[日上下午]/g, &#39;&#39;)dates.push(time.split(&#39;/&#39;))}return dates}
1 获取今年
let now &#61; new Date();let year &#61; now.getFullYear(); // 年
2 获取当月
let now &#61; new Date();let month &#61; now.getMonth() // 月
3 获取当日
let now &#61; new Date();let day &#61; now.getDate() // 日
4 获取周几
let now &#61; new Date();let weekday &#61; now.getDay(); // 日
5 获取时、分、秒、毫秒
let hour &#61; now.getHours();//时
let minu &#61; now.getMinutes();//分
let sec &#61; now.getSeconds();//秒
let ms &#61; now.getMilliseconds();//毫秒
6 获取昨天
let now &#61; new Date();
now.setTime(now.getTime()-24*60*60*1000);
var yesterday&#61; now.getFullYear()&#43;"-" &#43; (now.getMonth()&#43;1) &#43; "-" &#43; now.getDate();
7 获取明天
let now &#61; new Date();
now.setTime(now.getTime()&#43;24*60*60*1000);
var yesterday&#61; now.getFullYear()&#43;"-" &#43; (now.getMonth()&#43;1) &#43; "-" &#43; now.getDate();
Tips&#xff1a;【小程序云开发】中高级前端面试题库&#xff08;源码&#xff1a;小程序中联系我哟&#xff09;。
---------- 创作不易&#xff0c;感谢大家&#xff0c;请多多支持&#xff01;