/**
* 处理jxl中日期cell
*
* @param cell
* @param pattern 格式化日期的模式
* @return
*/
public String formatDataCell(Cell cell, String pattern) {
if(null == pattern || "".equals(pattern))pattern = "yyyy-MM-dd HH:mm:ss";
String dateStr = null;
SimpleDateFormat sdf=new SimpleDateFormat(pattern);
if (cell.getType() == CellType.DATE) {
dateStr = sdf.format(((DateCell)cell).getDate());
} else {
dateStr = cell.getContents();
}
sdf = null;
return dateStr;
}
/**
* 处理jxl中日期cell
*
* @param cell
* @param pattern 格式化日期的模式
* @return
*/
public Date formatDataCell(Cell cell, String pattern) {
if(null == pattern || "".equals(pattern))pattern = "yyyy-MM-dd";
Date date = null;
SimpleDateFormat sdf=new SimpleDateFormat(pattern);
if (cell.getType() == CellType.DATE) {
date = ((DateCell)cell).getDate();
} else {
String temp = cell.getContents();
if(null != temp && !"".equals(temp.trim())); {
try {
date = sdf.parse(temp.trim());
} catch (ParseException e) {
e.printStackTrace();
}
}
}
sdf = null;
return date;
}
|