jxl读取excel时间格式问题

来源:互联网 发布:恢复iphone软件 编辑:程序博客网 时间:2024/05/21 09:22

  public String getData(int cell, int row) {
  Cell rs = this.sheet.getCell(cell, row);
     if(rs.getType()==CellType.DATE){
      if(rs.getContents()!=null){
       SimpleDateFormat ds = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          DateCell dc = (DateCell)rs;
          Date date = dc.getDate();
    Calendar c=Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.HOUR, -8);//解析excel的时候会默认当前输入的时间为格林威治时间,需要转为当前时区的时间(之前8小时)
        return ds.format(c.getTime());      
      }
     }  
  return rs.getContents();
 }