Date and Time

Java program to convert java.util.Date to java.time.LocalDate Using Instance and ZonedDateTime

Table of Contents

Program

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
  
public class DateUtilDateToLocalDate  
{
    public static void main(String[] args)
    { 
        Date current = new Date();
        LocalDate local = current.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        System.out.println(local);
    }
}

Output

2021-05-17

Description

public Date()

Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

public Instant toInstant()

Converts this Date object to an Instant.
The conversion creates an Instant that represents the same point on the time-line as this Date.

Returns:

an instant representing the same point on the time-line as this Date object