package work.thirteen;
/*
* 国庆倒计时
创建一个国庆节2022年10月1日的日期对象gdDate
gdDate获取从1970年过了多少毫秒数
* */
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class GuoQing {
//倒计时
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);
}
}
}