bug 描述
Java 后台接收到的 excel 表中时间格式变为数字。
经过查找资料,该数字代表的是从 1990 年到该时间的天数。
so~ 通过一系列格式转换,转为正确的时间格式。
//if-else 判断时间的格式是否有效。
if(!checkDateValid(getCellValue(row.getCell(7)),format)){
Calendar calendar = new GregorianCalendar(1900,0,-1);
Date date = calendar.getTime();
//getCellValue(row.getCell(7) - 被转换为了天数。
Date dd = DateUtils.addDays(date,Integer.valueOf(getCellValue(row.getCell(7))));
//时间格式转换
sysUser.setBirthday(format.parse(format.format(dd)));
}else{
sysUser.setBirthday(format.parse(getCellValue(row.getCell(7))));
}
//该作用仅仅是为了判断时间格式是否被转换为数值类型。
private boolean checkDateValid(String date,SimpleDateFormat format){
try{
format.parse(date);
}catch(Exception e){
//not to do
return false;
}
return true;