java HSSFCell 導入獲取時間,通過時間戳轉換時間


 

今天導入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 }
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM