问题描述
- 求js大神~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if(orderTime+7天>当前时间){
alert(""订单时间已超过退差价范围!"");
window.close();
}如何让我获取到的orderTime能加上7天,和当前的时间比较呢,格式都要 yy-MM-dd
解决方案
<script type=""text/javascript"">function AddDays(datedays){ var nd = new Date(date); return calDays(nddays);}function calDays(nddays){ 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(str7);var curDate = calDays(new Date()0);if(strAdded>curDate){ alert(""大于"");}else{ alert(""不大于"");}</script>
解决方案二:
http://www.cnblogs.com/cm490893449/archive/2010/10/26/1861230.html
解决方案三:
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(""订单时间已超过退差价范围!"");
时间: 2024-11-03 21:41:36