文章目录
- 解决object转换Date问题
- 源代码
- List<Object>转换List<Date>问题
解决object转换Date问题
源代码
/**
* 解决object与Date转换问题
*/
@Test
public void t4() {
Object o = new Date();
String formatDate = DateFormatUtils.format((Date) o, com.alibaba.excel.util.DateUtils.DATE_FORMAT_16);
log.info("当前日期:【{}】",formatDate);
try {
Date date = DateUtils.parseDate(formatDate, com.alibaba.excel.util.DateUtils.DATE_FORMAT_16);
log.info("当前日期:【{}】",date);
} catch (ParseException e) {
log.error("error msg:【{}】",e);
throw new IllegalArgumentException(e);
}
}
22:30:01.864 [main] INFO com.geekmice.springbootselfexercise.NoDaoTest - 当前日期:【2023-08-06】
22:30:01.881 [main] INFO com.geekmice.springbootselfexercise.NoDaoTest - 当前日期:【Sun Aug 06 00:00:00 CST 2023】
List转换List问题
List<Object> list = new ArrayList(16);
list.add(new Date());
List<Date> newList = list.stream().map(item -> (Date) item).collect(Collectors.toList());
log.info("newList:【{}】",newList);
22:35:53.924 [main] INFO com.geekmice.springbootselfexercise.NoDaoTest - newList:【[Sun Aug 06 22:35:53 CST 2023]】