导入日期的有3种方式:
1.excel文档日期列设置为文本类型,用LocalDateTimeConverter.class
2.类中日期变量类型改为Date, 加上@DateTimeFormat
3.excel日期字段是按一定规则生成的数字,自定义转换器将数字转为日期,参考https://blog.csdn.net/qq_20009015/article/details/85243033
LocalDateTime:
public class LocalDateTimeConverter implements Converter {
@Override
public Class supportJavaTypeKey() {
return LocalDateTime.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public LocalDateTime convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return LocalDateTime.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
&