标签:
今天导入Excel的时候,后台java获取cell时间的时候,转换成了数字,该方法是把数字转换成时间类型的字符串
1 public static String getCell(HSSFCell cell) { 2 DecimalFormat df = new DecimalFormat("#"); 3 if (cell == null) 4 return ""; 5 switch (cell.getCellType()) { 6 case HSSFCell.CELL_TYPE_NUMERIC: 7 if(HSSFDateUtil.isCellDateFormatted(cell)){ 8 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 9 return sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())).toString(); 10 } 11 return df.format(cell.getNumericCellValue()); 12 case HSSFCell.CELL_TYPE_STRING: 13 System.out.println(cell.getStringCellValue()); 14 return cell.getStringCellValue(); 15 case HSSFCell.CELL_TYPE_FORMULA: 16 return cell.getCellFormula(); 17 case HSSFCell.CELL_TYPE_BLANK: 18 return ""; 19 case HSSFCell.CELL_TYPE_BOOLEAN: 20 return cell.getBooleanCellValue() + ""; 21 case HSSFCell.CELL_TYPE_ERROR: 22 return cell.getErrorCellValue() + ""; 23 } 24 return ""; 25 }
java HSSFCell 导入获取时间,通过时间戳转换时间
标签:
原文地址:http://www.cnblogs.com/lcgblog/p/4892518.html