Saturday, October 25, 2025
HomeLanguagesJavaLocalDate atStartOfDay() method in Java with Examples

LocalDate atStartOfDay() method in Java with Examples

The atStartOfDay() method of LocalDate class in Java is combines this date with the time of midnight to create a LocalDateTime at the start of this date. Syntax:

public ZonedDateTime atStartOfDay(ZoneId zone)

Parameter: This method accepts a parameter zone which is the zone ID to be used and not necessary null. The parameter is not mandatory. Return Value: It returns the local date-time of midnight at the start of this date, not null. Below programs illustrate the atStartOfDay() method of LocalDate in Java: Program 1: 

Java




// Program to illustrate the atStartOfDay() method
 
import java.util.*;
import java.time.*;
 
public class GfG {
    public static void main(String[] args)
    {
        // parses the local date
        LocalDate dt = LocalDate.parse("2019-11-01");
        System.out.println(dt);
 
        // Function call
        LocalDateTime dt1 = dt.atStartOfDay();
        System.out.println(dt1);
    }
}


Output:

2019-11-01
2019-11-01T00:00

Program 2: Program with parameters. 

Java




// Program to illustrate the atStartOfDay() method
 
import java.util.*;
import java.time.*;
 
public class GfG {
    public static void main(String[] args)
    {
 
        // parses the local date
        LocalDate dt = LocalDate.parse("2018-01-20");
        System.out.println(dt);
 
        // Function call
        ZonedDateTime dt1 = dt.atStartOfDay(ZoneId.systemDefault());
        System.out.println(dt1);
    }
}


Output:

2018-01-20
2018-01-20T00:00Z[Etc/UTC]

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#atStartOfDay()

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS