Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create LocalDate Object from Integers

Tags:

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.

like image 216
Greg Valvo Avatar asked Mar 15 '15 15:03

Greg Valvo


People also ask

How do I create a LocalDate instance?

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.

How do you create a LocalDate variable in Java?

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.

Which of the following method is used to create a specific LocalDate object?

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.


1 Answers

Use LocalDate#of(int, int, int) method that takes year, month and dayOfMonth.

like image 171
Rohit Jain Avatar answered Sep 23 '22 10:09

Rohit Jain