import org.apache.commons.lang3.time.DateUtils;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date now = new Date();
String formattedDateTime = DateUtils.format(now, "yyyy-MM-dd HH:mm:ss");
System.out.println(formattedDateTime);
}
}
import org.apache.commons.lang3.time.DateUtils;
import java.util.Date;
public class Main {
public static void main(String[] args) throws ParseException {
String dateTime = "2022-01-01 12:00:00";
Date parsedDate = DateUtils.parse(dateTime, "yyyy-MM-dd HH:mm:ss");
System.out.println(parsedDate);
}
}
import org.apache.commons.lang3.time.DateUtils;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date now = new Date();
Date addedDate = DateUtils.addDays(now, 7);
Date subtractedDate = DateUtils.addMonths(now, -1);
System.out.println("Added Date: " + addedDate);
System.out.println("Subtracted Date: " + subtractedDate);
}
}
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>