Java导入Excel文件日期解析成了中文问题解决

Excel文件日期为2018-12-12,在解析出来的时候变成了 12-十二月-2018

cell.setCellType(Cell.CELL_TYPE_STRING);//根据不同类型转化成字符串
使用了这个还是获取不到2018-12-12格式,但是我们获取到了他的天数。

那么我们就可以通过这个天数返回对应的日期格式:

	public static String importByExcelForDate(String value) {//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;
	}

猜你喜欢

转载自blog.csdn.net/weixin_43992507/article/details/85049287