本文主要是介绍Excle读取不同的时间格式进行不同的处理,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/***@description: 时间转字符串*@Param*@return*@author sunhao*@date 2021-04-30 11:01*/public static String dateToString(Cell cell) {short format = cell.getCellStyle().getDataFormat();Date dateCellValue = cell.getDateCellValue();String format1 ="";SimpleDateFormat sdf = null;if(format == 14){sdf = new SimpleDateFormat("yyyy-MM-dd");return sdf.format(dateCellValue);}if (format == 20){sdf = new SimpleDateFormat("HH:mm");return sdf.format(dateCellValue);}if (format == 21){sdf = new SimpleDateFormat("HH:mm:ss");return sdf.format(dateCellValue);}if (format == 31 ){sdf = new SimpleDateFormat("yyyy年MM月dd日");return sdf.format(dateCellValue);}if (format == 32){sdf = new SimpleDateFormat("HH时mm分");return sdf.format(dateCellValue);}if (format == 33){sdf = new SimpleDateFormat("HH时mm分mm秒");return sdf.format(dateCellValue);}if (format == 57){sdf = new SimpleDateFormat("yyyy年MM月");return sdf.format(dateCellValue);}if (format == 58){sdf = new SimpleDateFormat("MM月dd日");return sdf.format(dateCellValue);}if (format == 176){sdf = new SimpleDateFormat("yyyy-MM-dd");return sdf.format(dateCellValue);}sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");return sdf.format(dateCellValue);}
这篇关于Excle读取不同的时间格式进行不同的处理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!