Java Date vs. LocalDate

Sheeraz Gul Sep 16, 2022
Java Date vs. LocalDate

This tutorial demonstrates the difference between Date and LocalDate in Java.

Java Date vs. LocalDate

The Date class is from Java util package, and the LocalDate was added to the Time package of Java. Both classes are used for the date in Java; let’s see the main difference between Date and LocalDate in Java.

Date LocalDate
The java.util.Date is the core API for a date in Java from JDK 1.0. The java.time.LocalDate was introduced in the 1.8 version of Java.
The Date form util package also shows the time with the date. The LocalDate represents the date in ISO format yyyy-MM-dd without time. Mostly used to save dates like birthdays and paydays.
The Date was introduced in the 1.8 version of Java to provide immutability and thread safety. The LocalDate doesn’t support the immutability and thread safety.

Let’s try examples for both Date and LocalDate in Java.

the Date Class in Java

package delftstack;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Example {

	public static void main(String[] args) {

		//Create an Instant date and convert it to local date time.
		Instant Date_Instant = new Date().toInstant();
		LocalDateTime Demo_Date = LocalDateTime.ofInstant(Date_Instant,
		System.out.println("The Current Date is:  "+Demo_Date);

		//Create an Instant calendar
		Instant Calendar_Instant = Calendar.getInstance().toInstant();
		//Instance of zoneid to timezone
		ZoneId Default_TimeZone = TimeZone.getDefault().toZoneId();

		//from specific Calendar
		ZonedDateTime Gregorian_Calendar_DateTime = new GregorianCalendar().toZonedDateTime();

		//Date API Legacy classes
		Date Date_Demo = Date.from(;

		TimeZone Time_Zone = TimeZone.getTimeZone(Default_TimeZone);

		GregorianCalendar gc = GregorianCalendar.from(Gregorian_Calendar_DateTime);



The code above will use Java’s legacy Date API to show the current date and time with default and given timezones. See output:

The Current Date is:  2022-09-13T00:40:09.373
Tue Sep 13 12:40:09 PKT 2022

the LocalDate Class in Java

package delftstack;

import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;

public class Example {

	public static void main(String[] args) {

		//The Current Date
		LocalDate Current_LocalDate =;
		System.out.println("The Current Date is: "+Current_LocalDate);

		//The specific date Creation using LocalDate by providing input arguments
		LocalDate FirstLocalDate_2022 = LocalDate.of(2022, Month.JANUARY, 1);
		System.out.println("The Specific Date with inputs: "+FirstLocalDate_2022);

		//Trying to create a date by using Local date with invalid input
		LocalDate LocalDate_Karachi ="Asia/Karachi"));
		System.out.println("The Current Date in Karachi is: "+LocalDate_Karachi);

		//Trying to Get the date from the base date (1970-10-28)
		LocalDate LocalDate_FromBase = LocalDate.ofEpochDay(300);
		System.out.println("300th day from base date: "+LocalDate_FromBase);

		LocalDate HundredDay_2022 = LocalDate.ofYearDay(2022, 100);
		System.out.println("100th day of 2022: "+HundredDay_2022);


The code above uses LocalDate to get the current date, specific date, date from a particular timezone, and the date on a particular day of the year. See output:

The Current Date is: 2022-09-13
The Specific Date with inputs: 2022-01-01
The Current Date in Karachi is: 2022-09-13
300th day from base date: 1970-10-28
100th day of 2022: 2022-04-10

As we can see, the legacy Date API shows the full date with the current or given time, and it uses the instances of classes that provide more immutability and thread safety.

On the other hand, the LocalDate doesn’t show the time with the date, but the date can be manipulated using the LocalDate class from the time package of Java.

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

Related Article - Java Date