Java
Programming
Date Manipulation
Coding Tips
Time Management in Java

How do I get a Date without time in Java?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

In modern Java, the best way to represent a date without a time is to use LocalDate. It exists specifically for year-month-day values and avoids the confusion that comes from java.util.Date, which always represents a point in time. If you are working with newer Java code, the real answer is usually not "strip the time from Date" but "use the right type for a date-only value."

Use LocalDate for Date-Only Values

LocalDate is part of the java.time API introduced in Java 8. It has no hour, minute, second, or time zone component.

java
1import java.time.LocalDate;
2
3public class Main {
4    public static void main(String[] args) {
5        LocalDate today = LocalDate.now();
6        System.out.println(today);
7    }
8}

This prints a value like 2026-03-11 and does not carry any time-of-day state.

That is the cleanest representation for birthdays, due dates, calendar dates, and other date-only concepts.

Why java.util.Date Is Different

java.util.Date is not a date-only type. It represents an instant, which means it always includes time, even if formatting hides that fact.

This distinction matters because many bugs come from storing a date-only business concept in a timestamp type and then accidentally shifting it through time zones.

If you have control over the model, prefer LocalDate instead of trying to zero out a Date.

Convert a Legacy Date to LocalDate

If older APIs still return java.util.Date, convert it explicitly.

java
1import java.time.LocalDate;
2import java.time.ZoneId;
3import java.util.Date;
4
5public class Main {
6    public static void main(String[] args) {
7        Date legacyDate = new Date();
8
9        LocalDate localDate = legacyDate.toInstant()
10                .atZone(ZoneId.systemDefault())
11                .toLocalDate();
12
13        System.out.println(localDate);
14    }
15}

This is the usual bridge between old and new APIs.

If You Truly Need a Date at Midnight

Sometimes you still must pass a java.util.Date to a legacy API. In that case, you can derive a midnight timestamp from a LocalDate.

java
1import java.time.LocalDate;
2import java.time.ZoneId;
3import java.util.Date;
4
5public class Main {
6    public static void main(String[] args) {
7        LocalDate localDate = LocalDate.of(2026, 3, 11);
8
9        Date legacyDate = Date.from(
10                localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()
11        );
12
13        System.out.println(legacyDate);
14    }
15}

Be careful here: this is still a timestamp. It only looks like a date-only value because you chose midnight in one time zone.

Parsing a Date String Without Time

If the input is text such as 2026-03-11, parse it directly into LocalDate instead of parsing a full date-time first.

java
1import java.time.LocalDate;
2
3public class Main {
4    public static void main(String[] args) {
5        LocalDate date = LocalDate.parse("2026-03-11");
6        System.out.println(date);
7    }
8}

This keeps the value date-only from the beginning and avoids unnecessary conversions.

Formatting a Date Without Time

If the requirement is display rather than storage, format the LocalDate directly.

java
1import java.time.LocalDate;
2import java.time.format.DateTimeFormatter;
3
4public class Main {
5    public static void main(String[] args) {
6        LocalDate date = LocalDate.now();
7        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
8        System.out.println(date.format(formatter));
9    }
10}

This prints only the date portion because the underlying type itself has no time.

Common Pitfalls

  • Using java.util.Date when the business concept is really date-only.
  • Zeroing out time fields on a timestamp and assuming it is now a true date-only type.
  • Ignoring time zones when converting between Date and LocalDate.
  • Formatting away the time and assuming the stored value no longer contains one.
  • Mixing legacy and modern date APIs without explicit conversion.

Summary

  • In modern Java, use LocalDate for a date without time.
  • 'java.util.Date always represents a point in time, not a pure date.'
  • Convert legacy Date values to LocalDate when possible.
  • Only create a midnight Date when a legacy API forces you to.
  • Keep storage type and business meaning aligned to avoid date-time bugs.

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.