The atDate()
method is a part of LocalTime
class in the Java Date-Time API. This method combines this time with a date to create an instance of LocalDateTime
.
Here’s an example:
package org.kodejava.datetime;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
public class AtDateExample {
public static void main(String[] args) {
// Create a LocalTime instance
LocalTime time = LocalTime.of(14, 20);
// Create a LocalDate instance
LocalDate date = LocalDate.of(2023, 1, 23);
// Using atDate to combine time and date into a LocalDateTime
LocalDateTime dateTime = time.atDate(date);
System.out.println(dateTime);
}
}
Output:
2023-01-23T14:20
In this example, a LocalTime
and a LocalDate
are combined into a LocalDateTime
using the atDate()
method. This method is useful when you have a LocalTime
instance and want to combine it with a date. It’s in some sense a converse operation to LocalDate
‘s atTime()
.
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024