[bug] - 关于poi导入excel时间格式会减少8小时的问题.

这个bug发生在使用poi组件导入导出excel时,(这里是导入)

首先在excel中的格式设定是

yyyy-mm-dd hh:mm:ss

通过配套使用ExcelUtil中 getCellValue(Cell cell)获取单元格的类型

经过判定后,时间格式会进入:

            switch (cell.getCellType())
            {
                case NUMERIC: // 数字
                    if (HSSFDateUtil.isCellDateFormatted(cell))
                    {
                        double numericValue = cell.getNumericCellValue();
                        TimeZone zone = TimeZone.getTimeZone("GMT");
                        Date javaDate = DateUtil.getJavaDate(numericValue, zone);
                        System.out.println("javaDate:"+javaDate);
                        cellValue = javaDate;
                    }
                    else

但是之前的只是将返回的cellValue = 

cell.getDateCellValue();

这种获取时间的方式会少8个小时.

所以采用了上上面设置timezone.并通过DateUtil(poi的)getJavaDate传入该zone即可.

cell.getDateCellValue();

猜你喜欢

转载自www.cnblogs.com/ukzq/p/10452931.html
bug