If I already have a date's month, day, and year as integers, what's the best way to use them to create a LocalDate
object? I found this post String to LocalDate , but it starts with a String
representation of the date.
The easiest way to create an instance of the LocalDateTime class is by using the factory method of(), which accepts year, month, day, hour, minute, and second to create an instance of this class. A shortcut to create an instance of this class is by using atDate() and atTime() method of LocalDate and LocalTime class.
Another way to create a LocalDate is to create it from year, month and day information, like this: LocalDate localDate2 = LocalDate. of(2015, 12, 31); The LocalDate 's of() method creates a LocalDate instance representing a specific day of a specific month of a specific year, but without time zone information.
LocalDate is an immutable class that represents Date with default format of yyyy-MM-dd. We can use now() method to get the current date. We can also provide input arguments for year, month and date to create LocalDate instance.
Use LocalDate#of(int, int, int)
method that takes year, month and dayOfMonth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With