publicstaticvoidmain(String[] args)throwsParseException,InterruptedException{SimpleDateFormat sdf =newSimpleDateFormat("yyyy-MM-dd");Date gdDate = sdf.parse("2022-10-1");Calendar c =Calendar.getInstance();
c.setTime(gdDate);long gdMillis = c.getTimeInMillis();while(true){Date nowDate =newDate();
c.setTime(nowDate);long nowMillis = c.getTimeInMillis();long millis = gdMillis - nowMillis;//毫秒差long s = millis /1000;int day =(int) s /3600/24;//天int min =(int) s %3600/60+1;//分int ss =(int) s %3600%60+1;//秒System.out.println("距离国庆还有"+ day +"天"+ min +"分"+ ss +"秒");Thread.sleep(1000);if(millis <=0)break;}}