循环输出日期
答案:3 悬赏:20 手机版
解决时间 2021-03-21 18:40
- 提问者网友:書生途
- 2021-03-21 10:16
循环输出日期
最佳答案
- 五星知识达人网友:佘樂
- 2021-03-21 11:49
public static void main(String[] arg) throws Exception {
GregorianCalendar g = new GregorianCalendar();
g.setTime(new Date());
int day = g.get(Calendar.DAY_OF_YEAR);
int year = g.get(Calendar.YEAR);
for (int i = 0; i < 400; i++) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String formatTime = sdf.format(g.getTime());
System.out.println(formatTime);
if(g.get(Calendar.YEAR) > year) {
day = 0;
year = g.get(Calendar.YEAR);
}
g.set(Calendar.DAY_OF_YEAR, day + 1);
day++;
}
}
GregorianCalendar g = new GregorianCalendar();
g.setTime(new Date());
int day = g.get(Calendar.DAY_OF_YEAR);
int year = g.get(Calendar.YEAR);
for (int i = 0; i < 400; i++) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String formatTime = sdf.format(g.getTime());
System.out.println(formatTime);
if(g.get(Calendar.YEAR) > year) {
day = 0;
year = g.get(Calendar.YEAR);
}
g.set(Calendar.DAY_OF_YEAR, day + 1);
day++;
}
}
全部回答
- 1楼网友:上分大魔王
- 2021-03-21 14:12
Calendar c = Calendar.getInstance();
for(int i = 0; i < 400; i++) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String formatTime = sdf.format(c.getTime());
System.out.println(formatTime);
c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + 1);
}
for(int i = 0; i < 400; i++) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String formatTime = sdf.format(c.getTime());
System.out.println(formatTime);
c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + 1);
}
- 2楼网友:酒安江南
- 2021-03-21 12:37
一个for循环就搞定啦,呵呵
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯