private static String readTime(Cell cell){
if(cell==null){
return null;
}
// 单元格为日期格式
if(HSSFDateUtil.isCellDateFormatted(cell)){
Date date = cell.getDateCellValue();
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = s.format(date);
return time;
}
else{
// 单元格为自定义格式
if(cell.getCellTypeEnum() == CellType.NUMERIC){
Calendar ca = new GregorianCalendar(1900,0,-1);
Date time = ca.getTime();
Date date = DateUitls.addDays(time,(int)cell.getNumbericCellValue());
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = s.format(date);
return time;
}else {
// 单元格为文本格式
return cell.getStringCellValue();
}
}
}
读取excel中的时间
最新推荐文章于 2023-12-27 08:55:00 发布