I want to convert java.time.LocalDate
into java.util.Date
type. Because I want to set the date into JDateChooser
. Or is there any date chooser that supports java.time
dates?
Return value: This method returns the current date-time using the system clock.
When we're converting an Instant object, it's required to use a ZoneId because Instant objects are time-zone agnostic — just points on the timeline. The atZone(ZoneId zone) API from Instant object returns a ZonedDateTime, so we just need to extract LocalDate from it using the toLocalDate() method.
Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
That assumes your date chooser uses the system default timezone to transform dates into strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With