Date date = new Date();
ConversionService cs = DefaultConversionService.getSharedInstance();
cs.convert(date, Year.class);
cs.convert(date, YearMonth.class);
cs.convert(date, LocalDate.class);
cs.convert(date, LocalDateTime.class);
Feel free to close it if you don't think it's worthwhile.
Comment From: jhoeller
Since java.util.Date
conversions are rather messy except for a direct conversion to java.time.Instant
(which matches the Date
timestamp semantics), we intentionally limit the supported cases here. Also, since the logic is rather involved and spread out between java.time
and Joda-Time support, we're keeping it in dedicated subpackages where FormattingConversionService
picks it up, with a focus on conversion from String
but also some limited support for type-to-type conversion.