VOOZH about

URL: https://www.geeksforgeeks.org/java/java-current-date-time/

⇱ Java - Current Date and Time - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java - Current Date and Time

Last Updated : 11 Jul, 2025

In software development, we often work with dates and times. 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 class and we can import java.time package to work with date and time API. Here we are supposed to print the current date and time. There can be multiple ways to print the current date and time.

Different Ways To Get Current Date And Time

  1. Using Date Class
  2. Using get() method of the Calendar class
  3. Using calendar and formatter class to print the current dates in a specific format. 
  4. Using java.time.LocalDate
  5. Usingjava.time.LocalTime
  6. Using java.time.LocalDateTime
  7. Using java.time.Clock
  8. Using java.sql.Date

Using Date Class

Using Date Class in this method we will explore the date and time module provided by java.util.


Output
Current date is Thu Nov 30 07:45:38 UTC 2023



Using Calendar Instance

getInstance() method is generally used to get the time, date or any required some belonging to Calendar year.

Tip: Whenever we require anything belonging to Calendar, Calendar class is one of naive base for sure approach to deal with date and time instances.


Output
Day of week : 5
Day of year : 334
Week in Month : 5
Week in Year : 48
Day of Week in Month : 5
Hour : 7
Minute : 45
Second : 39
AM or PM : 0
Hour (24-hour clock) : 7



Using SimpleDateFormat

Using calendar and formatter class to print the current dates in a specific format.


Output
Formatted Date : 04-01-2024
Parsed Date : Sat Feb 18 00:00:00 UTC 1995

Using LocalDate, LocalTime, LocalDateTime

In this method we will discuss various date and time methods provided by java.time which


Output
Current date: 2024-01-04
Current time: 11:59:03.285876
Current date and time: 2024-01-04T11:59:03.286975

Using System Clock

This method we will discuss the use of clock method to fetch date and time provided by java.time package.


Output
Current instant: 2024-01-04T11:58:52.703945Z
Comment
Article Tags: