2006-12-01到2008-06-20杂遍历之间的日期??????(送高分)

liyanqing_01 2008-07-02 07:52:19
如何他们之间的每天都遍历出来?
...全文
88 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyanqing_01 2008-07-02
  • 打赏
  • 举报
回复
可以
谢谢
sd5816690 2008-07-02
  • 打赏
  • 举报
回复
两个版本,JAVA和javascript

package src.dyy.superSearch;

import java.util.Calendar;

public class Test1 {

public static void main(String[] args) {
Calendar date1 = Calendar.getInstance();
date1.set(2006, 11, 1, 0, 0, 0);// 月份从0开始
Calendar date2 = Calendar.getInstance();
date2.set(2008, 5, 20, 0, 0, 0);

while (date2.compareTo(date1) >= 0) {
System.out.println(date1.get(Calendar.YEAR) + "-"
+ (date1.get(Calendar.MONTH) + 1) + "-"
+ date1.get(Calendar.DATE));
date1.add(Calendar.DATE, 1);
}
}
}




<head>
<title> </title>
</head>

<body>

<script>
/**
* 时间对象的格式化;
*/
Date.prototype.format = function(format){
/*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}

if(/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}

for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
</script>
<script type="text/javascript">
var date1 = new Date("2006-12-01".replace(/-/g,"/"));
var date2 = new Date("2008-06-20".replace(/-/g,"/"));
while(date1.getTime() <= date2.getTime()){
document.write(date1.format("yyyy-MM-dd") + "<br/>");
date1.setDate(date1.getDate() + 1);
}
</script>

</body>
</html>
liyanqing_01 2008-07-02
  • 打赏
  • 举报
回复
那如果是闰年呢
每个月的天数也不是固定的?
能不能给具体点?
谢谢
  • 打赏
  • 举报
回复
用 Calendar 中的 add 方法,每次增加 1 天不就行了么?

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧