Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. 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 Date
    LocalDate date = LocalDate.now();
    System.out.println("Current Date: " + date);

    // Current Time
    LocalTime time = LocalTime.now();
    System.out.println("Current Time: " + time);

    // Current Date and Time
    LocalDateTime dateTime = LocalDateTime.now();
    System.out.println("Current DateTime: " + dateTime);

    // Formatting DateTime
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
    String formatted = dateTime.format(formatter);
    System.out.println("Formatted DateTime: " + formatted);
    }
    }
    Copied!

    Sample Output:

    Like
    Dislike
  2. Java Date and Time - W3Schools

    To display the current time (hour, minute, second, and nanoseconds), import the java.time.LocalTime class, and use its now()method:
    Java Dates

    Java does not have a built-in Date class, but we can import the java.timepackage to work with the date and time API. The package includes many date and time classes. For example:

    Display Current Date and Time

    To display the current date and time, import the java.time.LocalDateTime class, and use its now()method:

  3. 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 …

  4. 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 …

  5. 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( );...
  6. 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. …

  7. 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 …

  8. 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 …

  9. 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.

  10. 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...

  11. 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.