js或者jquery怎样获得前一天0点,前一周0点,指定月份的时间戳

获取到昨天0点的时间戳,上周一的时间戳(不是7天之前),上个月1号的时间戳。

// 今天
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);

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-03-30

// 今天

    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);

jQuery是一个快速、简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript。

jQuery设计的宗旨是“write Less,Do More”,即倡导写更少的代码,做更多的事情。

jQuery封装JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作、事件处理、动画设计和Ajax交互。

jQuery的模块可以分为:入口模块、底层支持模块和功能模块。

本回答被网友采纳