LocalTime atDate() method in Java with Examples
The atDate() method of a LocalTime class is used to combine this LocalTime Object with a LocalDate Object to create a LocalDateTime. All possible combinations of date and time are valid.
Syntax:
public LocalDateTime atDate(LocalDate date)
Parameters: This method accepts a single parameter date which is the date to combine with LocalTime Object, not null.
Return value: This method returns the LocalDateTime object after combining LocalTime and LocalDate, not null.
Below programs illustrate the atDate() method:
Program 1:
// Java program to demonstrate // LocalTime.atDate() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime Object LocalTime time = LocalTime.parse("09:32:42"); // create LocalDate Object LocalDate date = LocalDate.parse("2018-12-05"); // apply atDate() LocalDateTime local = time.atDate(date); // print LocalDateTime System.out.println("Date and Time:" + local.toString()); } } |
Date and Time:2018-12-05T09:32:42
Program 2:
// Java program to demonstrate // LocalTime.atDate() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime Object LocalTime time = LocalTime.parse("18:12:49"); // create LocalDate Object LocalDate date = LocalDate.parse("2017-12-05"); // apply atDate() LocalDateTime local = time.atDate(date); // print LocalDateTime System.out.println("Date and Time:" + local.toString()); } } |
Date and Time:2017-12-05T18:12:49
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#atDate(java.time.LocalDate)
Recommended Posts:
- OffsetTime atDate() method in Java with examples
- LocalTime with() Method in Java with Examples
- LocalTime from() method in Java with Examples
- LocalTime until() Method in Java with Examples
- LocalTime get() method in Java with Examples
- LocalTime plus() method in Java with Examples
- LocalTime getSecond() method in Java with Examples
- LocalTime toString() method in Java with Examples
- LocalTime getNano() method in Java with Examples
- LocalTime getMinute() method in Java with Examples
- LocalTime ofNanoOfDay() method in Java with Examples
- LocalTime isAfter() method in Java with Examples
- LocalTime isBefore() method in Java with Examples
- LocalTime getLong() method in Java with Examples
- LocalTime isSupported() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



