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

2025-02-25 14:19:23
推荐回答(2个)
回答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);

回答2:

// 今天

  1. var today = new Date();

  2. today.setHours(0);

  3. today.setMinutes(0);

  4. today.setSeconds(0);

  5. today.setMilliseconds(0);

  6. alert(today);

  7. var oneday = 1000 * 60 * 60 * 24;

// 昨天

  1. var yesterday = new Date(today - oneday);

  2. alert(yesterday);

// 上周一

  1. var lastMonday = new Date(today- oneday * (today.getDay() + 6));

  2. alert(lastMonday);

// 上个月1号

  1. var lastMonthFirst = new Date(today - oneday * today.getDate());

  2. lastMonthFirst = new Date(lastMonthFirst - oneday * (lastMonthFirst.getDate() - 1));

  3. alert(lastMonthFirst);

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

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

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

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