Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert java.time.LocalDate into java.util.Date type

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?

like image 463
Kavinda Gehan Avatar asked Apr 08 '14 06:04

Kavinda Gehan


People also ask

What does LocalDateTime NOW () return?

Return value: This method returns the current date-time using the system clock.

Can we convert date to LocalDate?

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.


1 Answers

Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); 

That assumes your date chooser uses the system default timezone to transform dates into strings.

like image 128
JB Nizet Avatar answered Sep 26 '22 18:09

JB Nizet