Using Java to calculate datetime, first consider the time class, Java provides in the time and date related classes, there is a calendar class, you can get a time and date.
To calculate the date 100 days after a certain date, the idea is as follows:
1. Set the time first, e.g. January 1, 2017;
2. Increase the number of days on a given date by 100;
The specific code is as follows:
1 /*2 * 1, first given a time, such as January 1, 20173 */4Calendar CLD =calendar.getinstance ();5Cld.set (Calendar.year, 2017);6Cld.set (calendar.monday,0);7Cld.set (calendar.date,1);8 9 //call Add () in the Calendar class to increase the amount of timeTenCld.add (calendar.date, 100); One ASystem.out.println ("Add 100 Days to Date:" +cld.get (calendar.year) + "year" +cld.get (calendar.month) + "Month" +cld.get (calendar.date) + "Day"); - -
The printing results are as follows:
Add 100 days to date: March 11, 2017
Adds or subtracts a specified amount of time for a given calendar field, based on the rules of the calendar. For example, to subtract 5 days from the current calendar time, you can do this by calling the following method:
field -Calendar field.
amount -The amount of date or time added to the field.
Calculate a date 100 days after a date in Java