- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
Java provides multiple ways to work with dates and times, primarily through the modern java.time API introduced in Java 8, which is more robust than the legacy java.util.Date and Calendar classes.
Example – Display current date, time, and formatted output:
import java.time.LocalDate;import java.time.LocalTime;import java.time.LocalDateTime;import java.time.format.DateTimeFormatter;public class Main {public static void main(String[] args) {// Current DateLocalDate date = LocalDate.now();System.out.println("Current Date: " + date);// Current TimeLocalTime time = LocalTime.now();System.out.println("Current Time: " + time);// Current Date and TimeLocalDateTime dateTime = LocalDateTime.now();System.out.println("Current DateTime: " + dateTime);// Formatting DateTimeDateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");String formatted = dateTime.format(formatter);System.out.println("Formatted DateTime: " + formatted);}}Copied!✕CopySample Output:
Like Dislike Java Date and Time - W3Schools
java.time (Java Platform SE 8 ) - Oracle
For lower level access to the fields refer to the java.time.temporal package. Each class includes support for printing and parsing all manner of dates and times. Refer to the java.time.format package for …
Java - Current Date and Time - GeeksforGeeks
Jul 11, 2025 · To accurately capture the current date and time is fundamental for various applications, such as scheduling tasks, tracking events, etc. In Java, there is a built-in class known as the Date …
Java - Date and Time - Online Tutorials Library
Java provides the Date class available in java.util package, this class encapsulates the current date and time.
Code sample
long start = System.currentTimeMillis( );System.out.println(new Date( ) + "\n");Thread.sleep(5*60*10);System.out.println(new Date( ) + "\n");long end = System.currentTimeMillis( );...Get the Current Date and Time in Java - Baeldung
Jan 8, 2024 · In this tutorial, we’ll explore how to work with dates and times in Java 8+ and prior environments. We’ll start by covering the modern Java 8+ java.time package, then look at legacy approaches for working with dates before Java 8. 2. …
Searches you might like
Mastering Java Time: A Comprehensive Guide - javaspring.net
Nov 12, 2025 · With the release of Java 8, the Java Date and Time API (JSR 310) was introduced, providing a more modern, easy - to - use, and thread - safe way to work with dates, times, and …
Java Clock Class - Complete Tutorial with Examples - ZetCode
Apr 16, 2025 · Clock can be used instead of System.currentTimeMillis(). Clock is abstract and immutable. It supports multiple time sources including fixed clocks for testing. The class helps make …
Java - Current Date and Time – TheLinuxCode
May 26, 2025 · In this guide, I‘ll walk you through everything you need to know about working with the current date and time in Java, from legacy approaches to modern best practices.
Java Date & Time Guide For Beginners | Medium
Mar 19, 2024 · In Java, dealing with date and time is a common but crucial task for many applications, ranging from logging and scheduling to handling user input and displaying information in different time...
How to Handle Time Code in Java: A Comprehensive Guide
Learn how to work with time code in Java, including best practices for converting time formats, detecting issues, and coding examples.