2 a1007790170 a1007790170 于 2015.07.22 11:47 提问

求js大神~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
js

if(orderTime+7天>当前时间){
alert("订单时间已超过退差价范围!");
window.close();
}

    如何让我获取到的orderTime能加上7天,和当前的时间比较呢,格式都要 yy-MM-dd

3个回答

danielinbiti
danielinbiti   Ds   Rxr 2015.07.22 12:18
 <script type="text/javascript">
function AddDays(date,days){
   var nd = new Date(date);
   return calDays(nd,days);
}
function calDays(nd,days){
   nd = nd.valueOf();
   nd = nd + days * 24 * 60 * 60 * 1000;
   nd = new Date(nd);
   //alert(nd.getFullYear() + "年" + (nd.getMonth() + 1) + "月" + nd.getDate() + "日");
var y = nd.getFullYear();
var m = nd.getMonth()+1;
var d = nd.getDate();
if(m <= 9) m = "0"+m;
if(d <= 9) d = "0"+d; 
var cdate = y+"-"+m+"-"+d;
return cdate;
}
var str='2015-06-22';
var strAdded = AddDays(str,7);
var curDate  = calDays(new Date(),0);
if(strAdded>curDate){
  alert("大于");
}else{
  alert("不大于");
}
</script>
caozhy
caozhy   Ds   Rxr 2015.07.22 13:05
showbo
showbo   Ds   Rxr 2015.07.22 15:24

    function OverDate(s, days) {
        s = '20' + s;
        var d = new Date(s.replace(/-/g, '/')), now = new Date();
        now = new Date(now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate());//去掉时间部分
        d.setDate(d.getDate() + days);
        return d.getTime() > now.getTime();
    }
    if (OverDate('15-07-16', 7)) alert("订单时间已超过退差价范围!");
    if (OverDate('15-07-13', 7)) alert("订单时间已超过退差价范围!");
Csdn user default icon
上传中...
上传图片
插入图片