private static void time(String sqlDate) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date jsDate = null;
try {
// 输入时间转为date
jsDate = sdf.parse(sqlDate);
} catch (ParseException e) {
e.printStackTrace();
}
// 获取当前时间
Date nowDate = new Date();
Long qdTime = nowDate.getTime();
Long jsTime = jsDate.getTime();
// 恢复成秒
Long xh = (jsTime - qdTime)/1000;
try {
String text = "离下班时间还有 ";
while (xh > 0) {
xh = xh - 5;
// int dd = (int) (xh / 60 / 60 * 24);
int hh = (int) (xh / 60 / 60 % 12);
int mm = (int) (xh / 60 % 60);
int ss = (int) (xh % 60);
System.out.println(text+""+ hh +" 小时 "+mm+" 分 "+ss+ " 秒");
Thread.sleep(5000);
if (hh == 0&mm == 0&& ss ==0){
break;
}
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) {
time("2021-12-21 18:30:00");
}
java倒计时
最新推荐文章于 2024-04-08 15:54:05 发布