求java怎么实现每循环一次时间增加一个小时并且有天数的增长

来源:百度知道 编辑:UC知道 时间:2024/06/01 13:08:31
求较简洁的代码

Calendar begin=Calendar.getInstance();
begin.setTime(....);//给定起始时间
//比如100小时
for(int i=0;i<100;i++){
//执行你的操作
begin.add(Calendar.HOUR,1);//增加了一小时
}

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class mao {
public static void main(String[] args) throws Exception {
Calendar c = Calendar.getInstance();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH");
while (true) {
c.add(c.HOUR_OF_DAY, 1);
System.out.println(df.format(c.getTime()));
Thread.sleep(10);
}
}
}