我想比較當前日期的日期,沒有采取一年進去了,我想改變文本的每一天如何比較當前日期的任何日期,不考慮今年考慮
這裏是我的代碼
TextView textView = (TextView)findViewById(R.id.textView);
String valid_until = "7/3";
String valid_until1 = "8/3";
String valid_until2 = "9/3";
String valid_until3 = "10/3";
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM");
Date strDate = null;
Date strDate1 = null;
Date strDate2 = null;
Date strDate3 = null;
try {
strDate = sdf.parse(valid_until);
strDate1 = sdf.parse(valid_until1);
strDate2 = sdf.parse(valid_until2);
strDate3 = sdf.parse(valid_until3);
} catch (ParseException e) {
e.printStackTrace();
}
if (new Date() == (strDate)) {
textView.setText("7 m");
}
if (new Date() == (strDate1)) {
textView.setText("8 m");
}
if (new Date() == (strDate2)) {
textView.setText("9 m");
}
if (new Date() == (strDate3)) {
textView.setText("10 m");
}
重複的:如何當天和一個月一天和一個月的java比較 (http://stackoverflow.com/a/39231958/642706) –