当前位置: 首页>>代码示例>>Java>>正文


Java DateUtil类代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.DateUtil的典型用法代码示例。如果您正苦于以下问题:Java DateUtil类的具体用法?Java DateUtil怎么用?Java DateUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DateUtil类属于org.apache.poi.ss.usermodel包,在下文中一共展示了DateUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNativeValueType

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
@Override
public ValueType getNativeValueType(int columnIndex) throws ParseException {
	Cell cell = getCurrentCell(columnIndex);
	final int type = cell.getCellType();
	if (type == Cell.CELL_TYPE_BLANK) {
		return ValueType.EMPTY;
	} else if (type == Cell.CELL_TYPE_STRING) {
		return ValueType.STRING;
	} else if (type == Cell.CELL_TYPE_NUMERIC) {
		if (DateUtil.isCellDateFormatted(cell)) {
			return ValueType.DATE;
		} else {
			return ValueType.NUMBER;
		}
	} else if (type == Cell.CELL_TYPE_FORMULA) {
		if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_NUMERIC) {
			return ValueType.NUMBER;
		} else {
			return ValueType.STRING;
		}
	} else {
		return ValueType.STRING;
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:25,代码来源:Excel2007ResultSet.java

示例2: getCellValue

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
/**
 * 获取单元格的值
 * 
 * @param cell
 * @return
 */
public static Object getCellValue(Cell cell) {
	Object cellValue = null;
	CellType cellType = cell.getCellTypeEnum();// CellType.forInt(cell.getCellType());
	if (cellType == CellType.STRING) {
		cellValue = cell.getStringCellValue();
	} else if (cellType == CellType.NUMERIC) {
		if (DateUtil.isCellDateFormatted(cell)) {
			cellValue = cell.getDateCellValue();
		} else {
			cellValue = cell.getNumericCellValue();
		}
	} else if (cellType == CellType.BOOLEAN) {
		cellValue = cell.getBooleanCellValue();
	} else if (cellType == CellType.FORMULA) {
		cellValue = cell.getCellFormula();
	} else if (cellType == CellType.BLANK) {
		cellValue = "";
	}
	return cellValue;
}
 
开发者ID:color-coding,项目名称:btulz.transforms,代码行数:27,代码来源:ExcelParser.java

示例3: getValueOrEmptyAsObject

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
public static Object getValueOrEmptyAsObject(FormulaEvaluator evaluator, Cell cell) {
    final CellValue cellValue = evaluator.evaluate(cell);
    if (cellValue == null) {
        return "";
    }
    switch (cellValue.getCellType()) {
        case Cell.CELL_TYPE_BOOLEAN:
            return Boolean.valueOf(cellValue.getBooleanValue());
        case Cell.CELL_TYPE_NUMERIC:
            if (DateUtil.isCellDateFormatted(cell)) {
                return cell.getDateCellValue();
            }
            BigDecimal bd = BigDecimal.valueOf(cell.getNumericCellValue()).setScale(DECIMAL_PRECISION, BigDecimal.ROUND_HALF_UP);
            return bd.stripTrailingZeros();
        case Cell.CELL_TYPE_STRING:
            return cellValue.getStringValue();
        case Cell.CELL_TYPE_ERROR:
            return "ERRO";
        default:
            return "";
    }
}
 
开发者ID:tecsinapse,项目名称:tecsinapse-data-io,代码行数:23,代码来源:ImporterUtils.java

示例4: formatRawCellContents

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
/**
 * 判断是否是日期,若是返回日期字符串,否则返回数字字符串
 *
 * @param value
 * @param formatIndex
 * @param formatString
 * @return
 */
private String formatRawCellContents(double value, int formatIndex, String formatString) {

    // Is it a date?
    if (DateUtil.isADateFormat(formatIndex, formatString)) {
        if (DateUtil.isValidExcelDate(value)) {

            Date d = DateUtil.getJavaDate(value);
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
            return f.format(d);
        }
    }
    String _value = NumberToTextConverter.toText(value);
    if (_value.indexOf('E') > -1) {
        //若是科学计数法,则转换为非科学计数法
        return new BigDecimal(value).toString();
    }
    return _value;
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:27,代码来源:XSSFSheetXMLHandlerPlus.java

示例5: getCellString

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
private String getCellString(Cell cell, boolean checkIfDate) {
	if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {			
		if (checkIfDate && cell.getCellType() != Cell.CELL_TYPE_STRING && DateUtil.isCellDateFormatted(cell)) {
			Date date = cell.getDateCellValue();
			return df.format(date);
		}
		else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
			String str = NumberToTextConverter.toText(cell.getNumericCellValue());
			if (str != null) str = str.replace(".", ",");
			return getStr(str);
		}
		else {
			cell.setCellType(Cell.CELL_TYPE_STRING);
			return getStr(cell.getStringCellValue());				
		}
	}
	return null;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:19,代码来源:TraceImporter.java

示例6: intercepterCellValue

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
public void intercepterCellValue(Cell cell, CellWrapper cellWrapper, String interceptor) throws Exception {
	if (cell == null) {
		cellWrapper.setValue(null);
	} else {
		int cellType = cell.getCellType();
		switch (cellType) {
		case Cell.CELL_TYPE_BLANK:
			cellWrapper.setValue(null);
			break;
		case Cell.CELL_TYPE_BOOLEAN:
			cellWrapper.setValue(Boolean.valueOf(cell.getBooleanCellValue()));
			break;
		case Cell.CELL_TYPE_ERROR:
			cellWrapper.setValue(cell.getErrorCellValue());
			break;
		case Cell.CELL_TYPE_FORMULA:
			cellWrapper.setValue(cell.getCellFormula());
			break;
		case Cell.CELL_TYPE_NUMERIC:
			if (DateUtil.isCellDateFormatted(cell)) {
				Date date = cell.getDateCellValue();
				cellWrapper.setValue(date);
			} else {
				cellWrapper.setValue(cell.getNumericCellValue());
			}
			break;
		case Cell.CELL_TYPE_STRING:
			cellWrapper.setValue(cell.getStringCellValue());
			break;
		}
	}
	logger.debug("before interceptor column number[" + cellWrapper.getColumn() + "] cell value[" + cellWrapper.getValue() + "] cell intercepter[" + interceptor + "]");
	this.intercepterCellValue(cellWrapper, interceptor);
	logger.debug("after interceptor  cell value[" + cellWrapper.getValue() + "]");

}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:37,代码来源:AbstractExcelParser.java

示例7: getCellPrimitiveValue

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
private static Object getCellPrimitiveValue(Cell cell, int cellType) {
	if (cellType == Cell.CELL_TYPE_NUMERIC) {
		if (DateUtil.isCellDateFormatted(cell)) {
			Calendar calendar = GregorianCalendar.getInstance();
			calendar.setTime(DateUtil.getJavaDate(cell.getNumericCellValue()));
			
			return calendar.getTime();
		} else {
			return DECIMAL_FORMAT.format(cell.getNumericCellValue());
		}
	} else if (cellType == Cell.CELL_TYPE_STRING) {
		if (StringUtils.hasText(cell.getStringCellValue())) {
			return cell.getStringCellValue();
		}
	}
	return null;
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:18,代码来源:WorkbookUtils.java

示例8: getStringValue

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
public String getStringValue(Cell cell) {
    if (cell == null) {
        return null;
    }
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_STRING:
        return cell.getStringCellValue();
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(cell)) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy'-'MM'-'dd");
            return format.format(cell.getDateCellValue());
        }
        return Double.toString(cell.getNumericCellValue());
    case Cell.CELL_TYPE_BOOLEAN:
        return Boolean.toString(cell.getBooleanCellValue());
    case Cell.CELL_TYPE_FORMULA:
        return getStringFormulaValue(cell);
    case Cell.CELL_TYPE_BLANK:
        return getStringRangeValue(cell);
    default:
        System.out.println(cell.getCellType());
        return null;
    }
}
 
开发者ID:cccties,项目名称:chilo-producer,代码行数:25,代码来源:ExcelReader.java

示例9: getCellValue

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
private Object getCellValue(Cell cellObject) {
	Object cellValue = null;
	if (cellObject != null) {
		switch (cellObject.getCellType()) {
		case HSSFCell.CELL_TYPE_BOOLEAN:
			cellValue = cellObject.getBooleanCellValue();
			break;

		case HSSFCell.CELL_TYPE_STRING:
			cellValue = cellObject.getStringCellValue();
			break;
		case HSSFCell.CELL_TYPE_NUMERIC:
			if (DateUtil.isCellDateFormatted(cellObject)) {
				cellValue = cellObject.getDateCellValue();
			} else {
				cellValue = cellObject.getNumericCellValue();
			}
			break;

		default:
			break;
		}
	}

	return cellValue;
}
 
开发者ID:sigmah-dev,项目名称:sigmah,代码行数:27,代码来源:ExcelImporter.java

示例10: convertToFieldType

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
private Object convertToFieldType(Object cellValue, Class<?> fieldType) {
  String value = String.valueOf(cellValue);
  if (fieldType == Double.class || fieldType == double.class) {
    return Double.valueOf(value);
  }
  if (fieldType == Integer.class || fieldType == int.class) {
    return Double.valueOf(value).intValue();
  }
  if (fieldType == Short.class || fieldType == short.class) {
    return Double.valueOf(value).shortValue();
  }
  if (fieldType == Long.class || fieldType == long.class) {
    return Double.valueOf(value).longValue();
  }
  if (fieldType == Float.class || fieldType == float.class) {
    return Double.valueOf(value).floatValue();
  }
  if (fieldType == Character.class || fieldType == char.class) {
    return value.charAt(0);
  }
  if (fieldType == Date.class) {
    return DateUtil.getJavaDate(Double.valueOf(value));
  }
  return value;
}
 
开发者ID:eBay,项目名称:xcelite,代码行数:26,代码来源:BeanSheetReader.java

示例11: getNumericDateType

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
@Test
public void getNumericDateType()
{
	double dateDouble = 35917.0;
	TimeZone utcTimeZone = TimeZone.getTimeZone(ZoneId.of("UTC"));
	Date javaDate = DateUtil.getJavaDate(dateDouble, utcTimeZone);

	when(cell.getCellTypeEnum()).thenReturn(NUMERIC);
	when(cell.getNumericCellValue()).thenReturn(dateDouble);
	when(cell.getDateCellValue()).thenReturn(javaDate);
	CellStyle cellStyle = mock(CellStyle.class);
	when(cell.getCellStyle()).thenReturn(cellStyle);
	short dataFormat = 0x0e;
	when(cellStyle.getDataFormat()).thenReturn(dataFormat);

	Object val = excelEntity.get("attr1");

	assertNotNull(val);
	assertEquals(val, "1998-05-02t00:00");
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:21,代码来源:ExcelEntityTest.java

示例12: isCellDateFormatted

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
/**
 * POIのDateUtilにあるメソッドが日本語を含む日付書式を正しく扱ってくれないので自力実装
 */
public static boolean isCellDateFormatted(Cell cell, double d) {
	if (cell == null) {
		return false;
	}
	boolean bDate = false;
	if (DateUtil.isValidExcelDate(d)) {
		CellStyle style = cell.getCellStyle();
		if (style == null) {
			return false;
		}
		int i = style.getDataFormat();
		String f = style.getDataFormatString();
		bDate = isADateFormat(i, f);
	}
	return bDate;
}
 
开发者ID:shunjikonishi,项目名称:excel2canvas,代码行数:20,代码来源:ExcelUtils.java

示例13: formatCellValue

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
public FormattedValue formatCellValue(Cell cell, FormulaEvaluator evaluator) {
	FormattedValue ret = doFormatCellValue(cell, evaluator);
	if (cell != null && cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
		ret.setFormula(cell.getCellFormula());
	}
	if (DEBUG && cell != null && cell.getCellStyle() != null) {
		int cellType = cell.getCellType();
		if (cellType == Cell.CELL_TYPE_FORMULA) {
			cellType = cell.getCachedFormulaResultType();
		}
		if (cellType == Cell.CELL_TYPE_NUMERIC) {
			System.out.println("Format: " + 
				cell.getCellStyle().getDataFormat() + ": " + 
				cell.getCellStyle().getDataFormatString() + " --- " + 
				ExcelUtils.isCellDateFormatted(cell) + ":" + 
				DateUtil.isCellDateFormatted(cell) + ":" + 
				DateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat()) + " --- " + 
				ret); 
		}
	}
	return ret;
}
 
开发者ID:shunjikonishi,项目名称:excel2canvas,代码行数:23,代码来源:DataFormatterEx.java

示例14: getCalField

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
private int getCalField(double serialDate) {
	// For some reason, a date of 0 in Excel gets shown
	//  as the non existant 1900-01-00
	if(((int)serialDate) == 0) {
		switch (_dateFieldId) {
			case Calendar.YEAR: return 1900;
			case Calendar.MONTH: return 1;
			case Calendar.DAY_OF_MONTH: return 0;
		}
		// They want time, that's normal
	}
	
	// TODO Figure out if we're in 1900 or 1904
	Date d = DateUtil.getJavaDate(serialDate, false);
	
	Calendar c = new GregorianCalendar();
	c.setTime(d);
	int result = c.get(_dateFieldId);
	
	// Month is a special case due to C semantics
	if (_dateFieldId == Calendar.MONTH) {
		result++;
	}
	
	return result;
}
 
开发者ID:shunjikonishi,项目名称:excel2canvas,代码行数:27,代码来源:Weekday.java

示例15: parseValue

import org.apache.poi.ss.usermodel.DateUtil; //导入依赖的package包/类
private Object parseValue( KCellType type, String vContent ) {
  if ( vContent == null ) {
    return null;
  }
  try {
    switch ( type ) {
      case NUMBER:
      case NUMBER_FORMULA:
        return Double.parseDouble( vContent );
      case BOOLEAN:
      case BOOLEAN_FORMULA:
        return vContent.equals( "1" );
      case DATE:
      case DATE_FORMULA:
        Double xlDate = Double.parseDouble( vContent );
        return DateUtil.getJavaDate( xlDate, DATE_TZ );
      case LABEL:
      case STRING_FORMULA:
      case EMPTY:
      default:
        return vContent;
    }
  } catch ( Exception e ) {
    return vContent;
  }
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:27,代码来源:StaxPoiSheet.java


注:本文中的org.apache.poi.ss.usermodel.DateUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。