java 怎样让一个日期累加,2010-12-16 累加到2010-12-30
答案:2 悬赏:50 手机版
解决时间 2021-02-22 22:23
- 提问者网友:听门外雪花风
- 2021-02-22 13:53
java 怎样让一个日期累加,2010-12-16 累加到2010-12-30
最佳答案
- 五星知识达人网友:猎心人
- 2021-02-22 15:21
用Calendar.set(Calendar.DATE, 1)就可以累加到12-30
import java.util.Calendar;
import java.util.Date;
public class CalendarAdd {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2012);
calendar.set(Calendar.MONTH, 12-1);//月份是从0开始的,所以要-1
calendar.set(Calendar.DATE, 16);
for(int i = 16; i <= 30; i++){
calendar.set(Calendar.DATE, i);
Date date = calendar.getTime();
System.out.println(date.toString());
}
}
}
-------------
Sun Dec 16 13:29:26 CST 2012
Mon Dec 17 13:29:26 CST 2012
Tue Dec 18 13:29:26 CST 2012
Wed Dec 19 13:29:26 CST 2012
Thu Dec 20 13:29:26 CST 2012
Fri Dec 21 13:29:26 CST 2012
Sat Dec 22 13:29:26 CST 2012
Sun Dec 23 13:29:26 CST 2012
Mon Dec 24 13:29:26 CST 2012
Tue Dec 25 13:29:26 CST 2012
Wed Dec 26 13:29:26 CST 2012
Thu Dec 27 13:29:26 CST 2012
Fri Dec 28 13:29:26 CST 2012
Sat Dec 29 13:29:26 CST 2012
Sun Dec 30 13:29:26 CST 2012
import java.util.Calendar;
import java.util.Date;
public class CalendarAdd {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2012);
calendar.set(Calendar.MONTH, 12-1);//月份是从0开始的,所以要-1
calendar.set(Calendar.DATE, 16);
for(int i = 16; i <= 30; i++){
calendar.set(Calendar.DATE, i);
Date date = calendar.getTime();
System.out.println(date.toString());
}
}
}
-------------
Sun Dec 16 13:29:26 CST 2012
Mon Dec 17 13:29:26 CST 2012
Tue Dec 18 13:29:26 CST 2012
Wed Dec 19 13:29:26 CST 2012
Thu Dec 20 13:29:26 CST 2012
Fri Dec 21 13:29:26 CST 2012
Sat Dec 22 13:29:26 CST 2012
Sun Dec 23 13:29:26 CST 2012
Mon Dec 24 13:29:26 CST 2012
Tue Dec 25 13:29:26 CST 2012
Wed Dec 26 13:29:26 CST 2012
Thu Dec 27 13:29:26 CST 2012
Fri Dec 28 13:29:26 CST 2012
Sat Dec 29 13:29:26 CST 2012
Sun Dec 30 13:29:26 CST 2012
全部回答
- 1楼网友:煞尾
- 2021-02-22 15:38
public class myclass {
public static void main(string[] args) {
int count= 0;
system.out.println("各变量的值:");
for (int i = 1; i < 100; i++) {
count+= i;
system.out.println(i);
if (count> 100)
break;
}
system.out.println("累加值:");
system.out.println(count);
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯