<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.10</version>
</dependency>
import org.joda.time.DateTime;
public class DateExample {
public static void main(String[] args) {
DateTime currentDate = new DateTime();
DateTime specifiedDate = new DateTime(2022, 1, 1, 0, 0, 0);
int year = currentDate.getYear();
int month = currentDate.getMonthOfYear();
int day = currentDate.getDayOfMonth();
DateTime modifiedDate = currentDate.plusDays(7);
String formattedDate = currentDate.toString("yyyy-MM-dd");
System.out.println("Current Date: " + formattedDate);
}
}
import org.joda.time.DateTime;
import org.joda.time.Days;
public class DateDifferenceExample {
public static void main(String[] args) {
DateTime startDate = new DateTime(2022, 1, 1, 0, 0, 0);
DateTime endDate = new DateTime(2022, 2, 1, 0, 0, 0);
int daysDifference = Days.daysBetween(startDate, endDate).getDays();
System.out.println("Days Difference: " + daysDifference);
}
}
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class DateFormatExample {
public static void main(String[] args) {
DateTime currentDate = new DateTime();
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
String formattedDate = formatter.print(currentDate);
System.out.println("Formatted Date: " + formattedDate);
}
}
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class DateParsingExample {
public static void main(String[] args) {
String dateString = "2022-01-01";
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime parsedDate = formatter.parseDateTime(dateString);
System.out.println("Parsed Date: " + parsedDate);
}
}