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

Calendar begin=Calendar.getInstance();begin.setTime(...);//给定起始时间 //比如100小时 for(int i=0;i
求java怎么实现每循环一次时间增加一个小时并且有天数的增长
Calendar begin=Calendar.getInstance();
begin.setTime(....);//给定起始时间
//比如100小时
for(int i=0;i<100;i++){
//执行你的操作
begin.add(Calendar.HOUR,1);//增加了一小时
}2009-11-14
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);
}
}
}2009-11-14
mengvlog 阅读 730 次 更新于 2025-10-29 20:10:20 我来答关注问题0
檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部