In this post, we can discuss how to get current date and time in Java.
These are some of the main new date classes that were introduced in Java 8.
- Instant represents date and time in UTC.
- LocalDate represents date.
- LocalTime represents time.
- LocalDateTime represents date and time without time zone.
- OffsetDateTime represents date and time with time zone offset.
- ZonedDateTime represents date and time with time zone information.
now() method can be used to find the current date and/or time in all of these classes.
Default system time zone is used when now() method is called for LocalDateTime, LocalDate, and LocalTime classes.