Excel日期处理

						short format = cell.getCellStyle().getDataFormat(); //其值为22   输入值类型为2018/6/28 17:25:48
						  if (format!=22) {
						        
							  cells[cellNum] = getCellValue(cell);
						}else {
							 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd  HH:mm:ss"); 
						        double value = cell.getNumericCellValue(); 
						        Date date = org.apache.poi.ss.usermodel.DateUtil 
						            .getJavaDate(value); 
						        cells[cellNum] = sdf.format(date);
						}

  

*万能处理方案:

所有日期格式都可以通过getDataFormat()值来判断

yyyy-MM-dd----- 14

yyyy年m月d日--- 31

yyyy年m月------- 57

m月d日  ---------- 58

HH:mm----------- 20

h时mm分  ------- 32

猜你喜欢

转载自www.cnblogs.com/ynhk/p/9254806.html