LocalDateTime.of()
时间: 2023-10-14 14:10:08 浏览: 68
LocalDateTime.of() is a method in the LocalDateTime class of the Java programming language. It is used to create a new instance of LocalDateTime with the specified values for year, month, day, hour, minute, second, and nanosecond.
The method has several overloaded versions, allowing the user to pass different combinations of arguments depending on their needs. For example, one can pass the year, month, and day values, or the year, month, day, hour, and minute values.
Here is an example of using LocalDateTime.of() to create a LocalDateTime instance with the date and time set to January 1, 2022, at 12:00 PM:
```
LocalDateTime dateTime = LocalDateTime.of(2022, 1, 1, 12, 0);
```
This will create a new LocalDateTime object with the specified values for year, month, day, hour, and minute. The second and nanosecond values will be set to zero by default.
阅读全文