DateTime dt = new DateTime(); // current date and time DateTime dtPlus2Hours = dt.plusHours(2); // add 2 hours to current date and time
DateTime dt = new DateTime("2021-10-10T11:30:00.000-07:00"); // specific date and time DateTime dtPlus3Hours = dt.plusHours(3); // add 3 hours to specific date and timeIn this example, the dtPlus3Hours DateTime object will be 3 hours ahead of the original dt DateTime object, which represents the specific date and time October 10, 2021 at 11:30:00 AM Pacific Time. The org.joda.time package provides many other classes and methods for working with dates and times in Java, including support for time zones, durations, periods, and more.