• 把excel导入的自定义时间改成yyyyMMdd


    public static String changeCellToString(XSSFCell cell){
    String result = "";
    // Object value = null;
    DecimalFormat df = new DecimalFormat("#");
    if (null != cell) {
    switch (cell.getCellType()) {
    case HSSFCell.CELL_TYPE_NUMERIC:// 数字类型
    if (HSSFDateUtil.isCellDateFormatted(cell)) {// 处理日期格式、时间格式
    SimpleDateFormat sdf = null;
    if (cell.getCellStyle().getDataFormat() == HSSFDataFormat
    .getBuiltinFormat("h:mm")) {
    sdf = new SimpleDateFormat("HH:mm");
    } else {// 日期
    sdf = new SimpleDateFormat("yyyyMMdd");
    }
    Date date = cell.getDateCellValue();
    result = sdf.format(date);
    } else if (cell.getCellStyle().getDataFormat() == 58) {
    // 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    double value = cell.getNumericCellValue();
    Date date = org.apache.poi.ss.usermodel.DateUtil
    .getJavaDate(value);
    result = sdf.format(date);
    } else {
    double value = cell.getNumericCellValue();
    CellStyle style = cell.getCellStyle();
    DecimalFormat format = new DecimalFormat();
    String temp = style.getDataFormatString();
    // 单元格设置成常规
    if (temp.equals("General")) {
    format.applyPattern("#");
    }
    result = format.format(value);
    }
    break;
    case HSSFCell.CELL_TYPE_STRING:// String类型
    result = cell.getRichStringCellValue().toString();
    break;
    case HSSFCell.CELL_TYPE_BLANK:
    result = "";
    default:
    result = "";
    break;
    }
    }
    return result;
    }
  • 相关阅读:
    使用Docker及k8s启动logstash服务
    在kubernetes上部署zookeeper,kafka集群
    k8s configmap 挂载配置文件
    k8s 安装 rabbitMQ 单机版
    aws 挂载efs (nfs)目录
    长白山游记
    RedHat 安装YUM软件
    mysql查询案例
    mysql子查询
    mysql联合查询
  • 原文地址:https://www.cnblogs.com/xlj227/p/6101454.html
Copyright © 2020-2023  润新知