我正在嘗試將字符串格式的日期與當(dāng)前日期進(jìn)行比較。這就是我的做法(尚未測試,但應(yīng)該可以工作),但是我使用的是不贊成使用的方法。有什么好的建議嗎?謝謝。PS:我真的很討厭用Java做Date的事情。做同一件事的方法有很多,以至于您真的不確定哪一種是正確的,因此我在這里提出問題。String valid_until = "1/1/1990";Calendar cal = Calendar.getInstance();SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");Date strDate = sdf.parse(valid_until);int year = strDate.getYear(); // this is deprecatedint month = strDate.getMonth() // this is deprecatedint day = strDate.getDay(); // this is deprecated Calendar validDate = Calendar.getInstance();validDate.set(year, month, day);Calendar currentDate = Calendar.getInstance();if (currentDate.after(validDate)) { catalog_outdated = 1;}
在Android中比較日期的最佳方法
拉風(fēng)的咖菲貓
2019-12-21 12:49:10