Convert LocalDate, LocalDateTime and ZonedDateTime to Date

This Convert LocalDate, LocalDateTime and ZonedDateTime to Date tutorial shows you my knowledge about conversion between LocalDate, LocalDateTime and ZonedDateTime to the classic java.util.Date in Java 8.

As you know the class java.util.Date represents a specific instant in time, with millisecond precision. It means that java.util.Date doesn’t contain time zone and only represents the number of seconds passed since the Unix epoch time – 1970-01-01T00:00:00Z (midnight at the start of January 1, 1970 GMT/UTC).

Convert LocalDate to Date

Or

Convert LocalDateTime to Date

Or

Convert ZonedDateTime to Date

Create a program for testing
Now, we create main class to show how the above examples works.

Run above main as Java application and produce the output like below

Convert LocalDate, LocalDateTime and ZonedDateTime to Date

That’s it on the tutorial Convert LocalDate, LocalDateTime and ZonedDateTime to Date in Java 8.

References
JSR 310: Date and Time API
Unix time
Instant JavaDoc

Leave a Comment

*

Please share it if you found this useful
Hide Buttons