js 获取今天以及前一周/前20天时间
生活随笔
收集整理的這篇文章主要介紹了
js 获取今天以及前一周/前20天时间
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
var end = new Date();
var start = new Date();
console.log('==========今天=============')
console.log(start);
console.log(end);
console.log('==========今天=============')
console.log(start.getFullYear());
console.log(start.getMonth());
console.log(start.getDate());
console.log('==========20天前=============')
start.setDate(start.getDate() - 20); //day和month會自動計算到上一個月的
console.log(start.getFullYear());
console.log(start.getMonth());
console.log(start.getDate());var startYear = start.getFullYear();
var startMonth = start.getMonth() + 1 >= 10 ? start.getMonth() + 1 : "0" + (start.getMonth() + 1);
var startDate = start.getDate() >= 10 ? start.getDate() : "0" + start.getDate();var endYear = end.getFullYear();
var endtMonth = end.getMonth() + 1 >= 10 ? end.getMonth() + 1 : "0" + (end.getMonth() + 1);
var endDate = end.getDate() >= 10 ? end.getDate() : "0" + end.getDate();
startDate1 = startYear + "-" + startMonth + "-" + startDate;
endDate1 = endYear + "-" + endtMonth + "-" + endDate;
console.log(startDate1);
console.log(endDate1)
console輸出:
?
轉載于:https://www.cnblogs.com/Andrew520/p/9317308.html
總結
以上是生活随笔為你收集整理的js 获取今天以及前一周/前20天时间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Floyd算法 笔记 C/C++
- 下一篇: mybaitis 通过Mapping 实