上代码
public class TimeTest {
public static long midTime;
public static void main(String[] args) {
Calendar instance = Calendar.getInstance();
instance.set(2022, 4, 29, 17, 30, 0);
long endTime = instance.getTimeInMillis();
Date date = new Date();
long startTime = date.getTime();
midTime = (endTime - startTime) / 1000;
time2();
}
private static void time2() {
while (midTime > 0) {
midTime--;
long hh = midTime / 60 / 60 % 60;
long mm = midTime / 60 % 60;
long ss = midTime % 60;
System.out.println("还有" + hh + "小时" + mm + "分钟" + ss + "秒");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
|