In the project, you need to determine whether the incoming date is within the next year. Baidu found no good way online, and wrote it to facilitate yourself and others:
int datecompareAfter = compareDate(new Date(), date); int daecompareBefore = compareDate(date, getOneYear()); if (datecompareAfter == -1 && daecompareBefore == -1) { //If it is not within one year, a prompt will pop up } else { //Logistics done within one year } // Compare the timepublic int compareDate(Date d1, Date d2) { if (() > ()) { return 1; } else if (() < ()) { return -1; } else {// Equalreturn 0; } } //The current time plus 1 yearpublic Date getOneYear() { Calendar c = (); (, 1); return (); }
The above example of the algorithm for determining whether the date is within one year of Android is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.