距离2022国庆倒计时
package Day0713;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
//倒计时
public class Two {
public static void main(String[] args) throws InterruptedException, ParseException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date endDate = dateFormat.parse("2022-10-01");
long endTime = endDate.getTime();
while (true){
Date date = new Date();
//当前时间戳
long starTime = date.getTime();
long djs = endTime - starTime;
//秒
int second = (int) (djs / 1000 % 60);
//分
int min = (int) (djs / 1000 /60 % 60);
//小时
int hour = (int) (djs / 1000 / 60 / 60 % 24);
//天
int day = (int)(djs / 1000 / 60 / 60 / 24);
System.out.println("距离10月1还有"+day+"天"+hour+"小时"+min+"分钟"+second+"秒");
Thread.sleep(1000);
}
}
}
暑期编程PK赛
得CSDN机械键盘等精美礼品!


