This post will discuss how to get a date without time in Java.

1. Using Joda Time Library

The Joda-Time date-time library provides the high-quality replacement of standard date and time classes prior to Java SE 8. To get the date without time, you can use the LocalDate class.

Download Code

Output (will vary):

2021-12-24

 
The Joda Time library DateTimeZone class provides access to the time zone through factory method forID():

Download Code

Output (will vary):

2021-12-24

2. Using LocalDate class

Similar to the Joda-Time library, Java 8 java.time package included a LocalDate class to represent a date without a time-zone.

Download  Run Code

Output (will vary):

2021-12-24

 
To obtain the current date in the specified time zone, you can specify a Zone ID to the LocalDate.now() method.

Download  Run Code

Output (will vary):

2021-12-24

3. Using Date object

The Date object is initialized with the current date and time when its no-arg constructor is called. To parse only date (without time) in the specified format, use the DateFormat class.

Download  Run Code

Output (will vary):

12-24-2021

4. Using Apache Commons Lang

The DateUtils class from Apache Commons Lang library provides a lot of useful utilities for Date and time manipulation. You can call its truncate() method to truncate a Date, as shown below.

Download Code

Output (will vary):

Sun Dec 24 00:00:00 PST 2021

That’s all about getting a date without time in Java.