date LocalDateTime
时间: 2023-10-26 07:28:24 浏览: 80
LocalDateTime is a class in Java that represents a date and time without a time zone. It is part of the java.time package and was introduced in Java 8.
You can use LocalDateTime to store and manipulate date and time values, such as year, month, day, hour, minute, and second. It does not contain any information about time zone or offset from UTC.
Here's an example of how you can create a LocalDateTime object:
```java
import java.time.LocalDateTime;
public class Main {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
System.out.println("Current date and time: " + now);
}
}
```
In this example, we use the `now()` method to get the current date and time. The `toString()` method is used to convert the LocalDateTime object to a string representation.
You can also create LocalDateTime objects by specifying specific values for year, month, day, hour, minute, and second using the `of()` method.
I hope this helps! Let me know if you have any more questions.
阅读全文