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?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Here's a utility class I use to convert the newer
java.time
classes tojava.util.Date
objects and vice versa:Edited based on @Oliv comment.
You can use
java.sql.Date.valueOf()
method as:No need to add time and time zone info here because they are taken implicitly.
See LocalDate to java.util.Date and vice versa simpliest conversion?
That assumes your date chooser uses the system default timezone to transform dates into strings.
In order to create a java.util.Date from a java.time.LocalDate, you have to
The code might look as follows:
This solution here is a bit longer and you could include something for the time here as well but as far as I understand your problem you just need the actual date.
Might not look that elegant but it works. Note: month-1 is used because the months in calendar start with 0.
This works for me:
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#toString--