Java Date and Time

Java Date and Time

In Java, working with date and time is mainly done using the classes from the java.time package (introduced in Java 8).
These classes are more powerful, accurate, and easier to use compared to older Date and Calendar classes.


✅ Import Required Package

import java.time.*;

 Get Current Date


 

✔ Output

Today's Date: 2025-12-08 (example)

 Get Current Time


 


 Get Current Date and Time


 


 Formatting Date and Time

Use DateTimeFormatter to format the output.


 

✔ Output

Formatted: 08-12-2025 10:45:30

 Custom Date Creation


 


 Comparing Dates


 


 Adding or Subtracting Time


 


 Working with Time Zones


 


 Measure Time Duration


 

✔ Output

Minutes difference: 150

🏁 Summary

Feature Example
Get current date LocalDate.now()
Get current time LocalTime.now()
Format date/time DateTimeFormatter
Modify date/time .plus(), .minus()
Compare .isBefore(), .isAfter()
Time zones ZonedDateTime

You may also like...