I want to create a remainder app for my project. For that I'm trying to compare the User given date and the system date. If they equals then the alarm need to be set on the particular day. The date will be in an SQLlite database table. I've no idea.
Asked
Active
Viewed 47 times
0
-
1Make sure you get ISO 8601 compliant dates in a certain format and you can simply compare them using Java's `LocalDateTime`, `Instant`, etc. classes available in Java 8 and onwards. – Ben Jun 13 '18 at 10:59
-
Questions on this subject have been asked 100 times before. Please use your search engine rather than asking the same question again. Because you’ll find many good answers faster that way. – Ole V.V. Jun 13 '18 at 14:08
1 Answers
0
Use SimpleDateFormat:
If your date is in 31/12/2014 format.
String my_date = "31/12/2014"
Then you need to convert it into SimpleDateFormat
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date strDate = sdf.parse(my_date);
if (new Date().after(strDate))
{
your_date_is_outdated = true;
}
else
{
your_date_is_outdated = false;
}
-
Please don’t teach the young ones to use the long outdated and notoriously troublesome `SimpleDateFormat` class. At least not as the first option. And not without any reservation. Today we have so much better in [`java.time`, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/) and its `DateTimeFormatter`. Yes, you can use it on Android. For older Android see [How to use ThreeTenABP in Android Project](https://stackoverflow.com/questions/38922754/how-to-use-threetenabp-in-android-project). – Ole V.V. Jun 13 '18 at 14:05