zoukankan      html  css  js  c++  java
  • JXL读取Excel日期时间不准确

    XL读取Excel日期时间多出了8个小时。

                        Cell c = rs.getCell(j, i);
                        if (c.getType() == CellType.DATE) {//手动填写模板文件时为 date 类型,其他情况有可能不是date类型
                            DateCell dc = (DateCell) c;
                            Date date = dc.getDate();
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            String sDate = sdf.format(date);
                            nextLine[j] = sDate;
                        }
                        else {
                            String d = rs.getCell(j, i).getContents().trim();
                            nextLine[j] = d;
                        }

    解决办法:获取的日期时间需要调整时区。参见:http://www.andykhan.com/jexcelapi/tutorial.html#dates

                        Cell c = rs.getCell(j, i);
                        if (c.getType() == CellType.DATE) {//手动填写模板文件时为 date 类型,其他情况有可能不是date类型
                            DateCell dc = (DateCell) c;
                            Date date = dc.getDate();
                            TimeZone zone = TimeZone.getTimeZone("GMT");
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            sdf.setTimeZone(zone);
                            String sDate = sdf.format(date);
                            nextLine[j] = sDate;
                        }
                        else {
                            String d = rs.getCell(j, i).getContents().trim();
                            nextLine[j] = d;
                        }

  • 相关阅读:
    Linux性能优化之CPU优化(一)
    MongoDB CPU使用较高,如何排查?
    MongoDB 安全配置
    open-falcon v0.2 监控部署记录
    有关redis相关的性能优化及内存说明
    kafka 基础知识梳理
    Java 进程占用 VIRT 虚拟内存超高的问题研究
    【nodejs】文件上传demo实现
    translate和position的比较
    setAttribute()、getAttribute()与ele[attr]与自定义属性
  • 原文地址:https://www.cnblogs.com/toSeeMyDream/p/4795679.html
Copyright © 2011-2022 走看看