I want to compare the date with the current date, without taking the year into account, and I want to change the text for each day
Here is my code
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");
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…