public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long time = sdf.parse("2022-03-21 23:59:59", new ParsePosition(0)).getTime();
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
long ns = 1000;
// // 獲得兩個時間的毫秒時間差異
long diff = time - System.currentTimeMillis() + 1000;
// // 計算差多少天
long day = diff / nd;
// // 計算差多少小時
long hour = diff % nd / nh;
// // 計算差多少分鍾
long min = diff % nd % nh / nm;
// 計算差多少秒//輸出結果
long sec = diff % nd % nh % nm / ns;
System.out.println(day + "天" + hour + "小時" + min + "分鍾" + sec + "秒");
}