The Java Date and Time API (java.time) was introduced in Java 8 to fix the problems of older classes like Date and Calendar. It is immutable, thread-safe, and much easier to understand and use.
All modern date and time classes are available inside the java.time package. These classes are immutable, meaning once created, their values cannot be changed. Any modification returns a new object.
// Creating and displaying current date
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate today = LocalDate.now();
System.out.println(today);
}
}
// Working with date and time together
import java.time.LocalDateTime;
public class Main {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
System.out.println(now);
}
}
2025-12-18
2025-12-18T12:30:45.123
The output depends on the current system date and time. The T separates date and time as per ISO-8601 standard.
See how Java methods manipulate time in real-time.
Updates every second (nanoseconds hidden)
Click buttons to modify the date object
java.time over legacy Date and CalendarLocalDate for birthdays and holidaysZonedDateTime for global applicationsPeriod