JAVA解析excel 时间格式数据

excel中数据明明是yyyy/mm/dd ,java程序解析为dd-M月-yyyy

最终解决方式:
//先解析成天数
public static String getValue(Cell cell) {
if (cell.getCellType() == CellType.BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == CellType.NUMERIC) {
double value = cell.getNumericCellValue();
return new BigDecimal(value).toString();
} else if (cell.getCellType() == CellType.STRING) {
return String.valueOf(cell.getStringCellValue());
} else {
return String.valueOf(cell.getStringCellValue());
}
}
//再转成日期格式字符串
public static String importByExcelForDate(String value) {
String currentCellValue = “”;
if(value != null && !value.equals(“”)){
Calendar calendar = new GregorianCalendar(1900,0,-1);
Date d = calendar.getTime();
Date dd = DateUtils.addDays(d,Integer.valueOf(value));
DateFormat formater = new SimpleDateFormat(“yyyy-MM-dd”);
currentCellValue = formater.format(dd);
}
return currentCellValue;
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部