JS時間操作

獲得前一天0點,前一週0點,指定月份的時間戳



// 今天
var today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
alert(today);
var oneday = 1000 * 60 * 60 * 24;
// 昨天
var yesterday = new Date(today - oneday);
alert(yesterday);
// 上週一
var lastMonday = new Date(today- oneday * (today.getDay() + 6));
alert(lastMonday);
// 上個月1號
var lastMonthFirst = new Date(today - oneday * today.getDate());
lastMonthFirst = new Date(lastMonthFirst - oneday * (lastMonthFirst.getDate() - 1));
alert(lastMonthFirst);
發佈了26 篇原創文章 · 獲贊 5 · 訪問量 31萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章