Given a Date dt you have several possibilities:
Solution 1: You can use the Calendar class for that:
Date dt = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.DATE, 1);
dt = c.getTime();
Solution 2: You should seriously consider using the Joda-Time library, because of the various shortcomings of the Date class. With Joda-Time you can do the following:
Date dt = new Date();
DateTime dtOrg = new DateTime(dt);
DateTime dtPlusOne = dtOrg.plusDays(1);
Solution 3: With Java 8 you can also use the new JSR 310 API (which is inspired by Joda-Time):
Date dt = new Date();
LocalDateTime.from(dt.toInstant()).plusDays(1);
Solution 4: With org.apache.commons.lang3.time.DateUtils you can do:
Date dt = new Date();
dt = DateUtils.addDays(dt, 1)
Answer from Daniel Rikowski on Stack OverflowGiven a Date dt you have several possibilities:
Solution 1: You can use the Calendar class for that:
Date dt = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.DATE, 1);
dt = c.getTime();
Solution 2: You should seriously consider using the Joda-Time library, because of the various shortcomings of the Date class. With Joda-Time you can do the following:
Date dt = new Date();
DateTime dtOrg = new DateTime(dt);
DateTime dtPlusOne = dtOrg.plusDays(1);
Solution 3: With Java 8 you can also use the new JSR 310 API (which is inspired by Joda-Time):
Date dt = new Date();
LocalDateTime.from(dt.toInstant()).plusDays(1);
Solution 4: With org.apache.commons.lang3.time.DateUtils you can do:
Date dt = new Date();
dt = DateUtils.addDays(dt, 1)
Date today = new Date();
Date tomorrow = new Date(today.getTime() + (1000 * 60 * 60 * 24));
Date has a constructor using the milliseconds since the UNIX-epoch. the getTime()-method gives you that value. So adding the milliseconds for a day, does the trick. If you want to do such manipulations regularly I recommend to define constants for the values.
Important hint: That is not correct in all cases. Read the WARNING comment, below.
Looking for help on Java Script that adds 50 days to current date
Creating a while loop calendar.
Videos
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Calendar c = Calendar.getInstance();
c.setTime(new Date()); // Using today's date
c.add(Calendar.DATE, 5); // Adding 5 days
String output = sdf.format(c.getTime());
System.out.println(output);
java.time
With the Java 8 Date and Time API you can use the LocalDate class.
LocalDate.now().plusDays(nrOfDays)
See the Oracle Tutorial.
Hello All,
I was tasked at work to develop a dynamic stamp to use on our Kofax Power PDF documents. So i made the stamp form and now I am to the point where i need some help. Part of the STAMP needs to display the date that is 50 calendar days from the current date. I can get to where the current date is displayed.
event.value = (new Date()).toString();
AFDate_FormatEx("mmm/dd/yyyy");
This is the code as it appears in my JavaScript editor, within Power PDF. That code displays:
Oct/16/2024
What I need it to display is the date that is 50 days in the future. Ive tried using ChatGPT and it spits out the code but it doesn't work when I paste it. What am I missing? Any help would be appreciated.
Thanks!