前一天
var time=(new Date).getTime()-24*60*60*1000;
var yesday=new Date(time);
var month=yesday.getMonth();
var day=yesday.getDate();
yesday=yesday.getFullYear() + "-" + (yesday.getMonth()> 9 ? (yesday.getMonth() + 1) : "0" + (yesday.getMonth() + 1)) + "-" +(yesday.getDate()> 9 ? (yesday.getDate()) : "0" + (yesday.getDate()));
打印结果
当天
var myDate = new Date(); //获取当前年份(2位)
var year=myDate.getFullYear(); //获取完整的年份(4位,1970-????)
var month=myDate.getMonth(); //获取当前月份(0-11,0代表1月)
var day=myDate.getDate(); //获取当前日(1-31)
var dayNow=year+'-'+(month+1)+"-"+day;
打印结果
网友评论