at() Methods
Description
atXXX()
creates a new datetime object from an existing datetime object with
additional information.
Example
The following code use at method to add additional information to a date object.
import java.time.LocalDate;
import java.time.LocalDateTime;
//w w w . java 2s . com
public class Main {
public static void main(String[] args) {
LocalDate localDate = LocalDate.of(2014, 6, 21);
System.out.println(localDate);
LocalDateTime localTime1 = localDate.atStartOfDay();
System.out.println(localTime1);
LocalDateTime localTime2 = localDate.atTime(16, 21);
System.out.println(localTime2);
}
}
The code above generates the following result.
Example 2
The following code shows how to use atXXX() methods which supports the builder pattern to build a local date:
import java.time.LocalDate;
import java.time.Year;
// ww w .j av a 2 s . c o m
public class Main {
public static void main(String[] args) {
LocalDate localDate = Year.of(2014).atMonth(6).atDay(21);
System.out.println(localDate);
}
}
The code above generates the following result.