I thank you for possible answers. The problem is, I work with a legacy system with Java 1.4. In a registration form you have the following fields: 'Period' in the mm / yyyy format 'Expiration Day' Concatenate the day with the period and parse for Date.
I need to handle the months with 29 for February and the months of 31 days. Putting 'Expiration Day' = 31, when it is February the parse plays for 03/01/2021 and in the months when it is not 31 the parse plays for the first day of the following month. I need that for these situations the parse takes the last day of the month and not the following month. I have already researched and did not see how to do it by parse itself.
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date dataDebito = df.parse(31 + "/" + 02 + "/" + 2021); //February is not 31 and I need you to parse it for 2/28/2021 or 2/29/2021 if it was a leap year.
I will present solutions for different Java versions.
Java 8 and later: java.time
I recommend that you use java.time, the modern Java date and time API, for your date work.
Output:
Java 6 and 7: java.time through ThreeTen Backport
Code is the same as above. java.time has been backported to Java 6 and 7 in the ThreeTen Backport project. Link is at the bottom.
Java 1.5: Joda-Time
Java 1.1 through 1.4: Calendar
Links
java.timewas first described.java.timeto Java 6 and 7 (ThreeTen for JSR-310).