當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。