How to work with date and time in java?

The Java 8 Date and Time API provides comprehensive capabilities for date and time operations.

Example:


  LocalDateTime now = LocalDateTime.now();
  System.out.println("Current date and time: " + now);
  

Solution:

Manipulating and formatting date/time:


  LocalDateTime tomorrow = now.plusDays(1);
  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  System.out.println(tomorrow.format(formatter));
  

Beginner's Guide to Java