日期:2014-05-16 浏览次数:20350 次
<script> d1 = new Date(2009,11,1) d2 = new Date(2010,2,31) s = [] days = (Date.parse(d2)-Date.parse(d1))/1000/60/60/24 for(i = 0;i<=days;i++) { d = new Date(2009,11,1+i) d = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate() s.push(d) } document.write(s.join("<br/>")) </script>
------解决方案--------------------
//YYYY-MM-DD格式输入 function Todo(begin, end) { var ab = begin.split("-"); var ae = end.split("-"); var db = new Date(); db.setFullYear(ab[0], ab[1]-1, ab[2]); var de = new Date(); de.setFullYear(ae[0], ae[1]-1, ae[2]); var a = []; for (var i=0,temp=db;temp < de;i++) { a[i] = GetDate(temp); temp.setTime(temp.getTime() + 24*60*60*1000); } a[i] = GetDate(de); return a.join(); } //返回1900-01-01格式的字符串 function GetDate(d) { return d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate(); } document.write(Todo("2009-12-31", "2010-03-31"));
------解决方案--------------------