标签:date() bsp div count set new 获取 add fun
一、JS获取最近多少天日期
<script> function GetDateStr(AddDayCount) { var dd = new Date(); dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期 var y = dd.getFullYear(); var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1); //获取当前月份的日期,不足10补0 var d = d.getDate() < 10 ? "0" + dd.getDate() : dd.getDate(); //获取当前几号,不足10补0 return y + "-" + m + "-" + d; } document.write("前天:"+GetDateStr(-2)); document.write("<br />昨天:"+GetDateStr(-1)); document.write("<br />今天:"+GetDateStr(0)); document.write("<br />明天:"+GetDateStr(1)); document.write("<br />后天:"+GetDateStr(2)); document.write("<br />大后天:"+GetDateStr(3)); </script>
标签:date() bsp div count set new 获取 add fun
原文地址:http://www.cnblogs.com/alqscool/p/7993922.html