/**
* Title:
* Packet:com.lg.handlers
* Description:計算寫博客的時間
* Author:LG
* Create Date: 2020/3/31.
* Modify User:
* Modify Date:
* Modify Description:
*/
public class testTime {
public static void main(String[] args) throws ParseException {
System.out.println("您開始寫博客的時間(yyyy-mm-dd):");
String str = new Scanner(System.in).nextLine();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(str);
System.out.println("您放棄寫博客的時間(yyyy-mm-dd):");
String str1 = new Scanner(System.in).nextLine();
SimpleDateFormat dsdf1 = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = dsdf1.parse(str1);
long time = date1.getTime()-date.getTime();
time = time/1000/24/60/60;
System.out.println("哇偶,您寫博客已經"+time+"天了呢");
}
}
實現結果不重要,重要的是格式一定要規範.哈哈哈~