日期:2014-05-16  浏览次数:20342 次

怎么获取前一天的时间呢
我需呀在页面上获取前一天的时间,作为参数传入数据库查询.代码如下,这样存在着月初,年初时间错误的问题,有没有高人给出好方法啊.
function wuhuinput() {
  var now = new Date();
  var wuhu_date = (now.getYear() + "-" + (now.getMonth() + 1) + "-" + (now.getDate() - 1));
  $('#wuhudate').ajaxSubmit({
  target: '#inputwuhudate',
  url: '<c:url value="/inputwuhudate/savewhdate.do?wuhu_date="/>' + wuhu_date,
  dataType: "json",
  success: function(data) {
  if (data.msg.flag == 1) {
  alert(data.msg.msg);
  $('#wuhudate').submit();
  }
  else {
  alert(data.msg.msg);
  }
  },
  error: function(a, b, c) {
  alert("请求失败!" + $(c).text());
  }
  });
  }

------解决方案--------------------
哦 明白你的意思了
var d=new Date();
var daybeofore=d.getTime()-24*3600*1000;
d=new Date(daybefore);//前一天的日期
之后getFullYear之类的分解试试
------解决方案--------------------
HTML code

var now = new Date()
//取昨天。会自动换算年月。
now.setDate(now.getDate() - 1);

------解决方案--------------------
JScript code

Date.prototype.addDay = function(num) {
    this.setDate(this.getDate() + num);
    return this;
};
var now = new Date();
now.addDay(-1);