當前位置: 首頁>>代碼示例>>Java>>正文


Java DateUtil.getJavaDate方法代碼示例

本文整理匯總了Java中org.apache.poi.ss.usermodel.DateUtil.getJavaDate方法的典型用法代碼示例。如果您正苦於以下問題:Java DateUtil.getJavaDate方法的具體用法?Java DateUtil.getJavaDate怎麽用?Java DateUtil.getJavaDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.ss.usermodel.DateUtil的用法示例。


在下文中一共展示了DateUtil.getJavaDate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: getDate

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
@Override
public Date getDate(int columnIndex) throws ParseException {
	String dateValue = getValue(columnIndex);
	if (dateValue == null) {
		return null;
	}
	switch (getCellType(columnIndex)) {
		case NUMBER:
		case DATE:
			// XLSX stores dates as double values
			double dateAsDouble = Double.parseDouble(dateValue);

			// Use POI methods to convert value to Date java object
			if (DateUtil.isValidExcelDate(dateAsDouble)) {
				return DateUtil.getJavaDate(dateAsDouble, xlsxWorkbook.isDate1904);
			} else {
				throw new ParseException(new ParsingError(getCurrentRow() + 1, columnIndex,
						ParsingError.ErrorCode.UNPARSEABLE_DATE, dateValue));
			}
		case INLINE_STRING:
		case SHARED_STRING:
		case STRING:
			// In case a date is stored as String, we try to parse it here
			String dateString = dateValue;
			try {
				return dateFormatProvider.geDateFormat().parse(dateString);
			} catch (java.text.ParseException e) {
				throw new ParseException(new ParsingError(getCurrentRow() + 1, columnIndex,
						ParsingError.ErrorCode.UNPARSEABLE_DATE, dateString));
			}
		default:
			throw new ParseException(new ParsingError(getCurrentRow() + 1, columnIndex,
					ParsingError.ErrorCode.UNPARSEABLE_DATE, dateValue));

	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:37,代碼來源:XlsxResultSet.java

示例7: getValue

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
/** 從表格之中讀取數據並進行處理
 * @param fieldInfo 
 * @param cell 當前cell
 * @return
 * @throws Exception
 */
public  static Object getValue(ImportFieldInfo fieldInfo, Cell cell) throws Exception{
	int size = fieldInfo.getTypeChain().size();
	Class<?> type = fieldInfo.getTypeChain().get(size - 1);
	String dateFormat = fieldInfo.getDateFormat();
	int cellType = cell.getCellType();
	Object obj = null ;
	switch (cellType) {
	case Cell.CELL_TYPE_BLANK:
		return null;
		
	case Cell.CELL_TYPE_BOOLEAN:
		obj = cell.getBooleanCellValue();
		break;
		
	case Cell.CELL_TYPE_STRING:
		obj = cell.getStringCellValue();
		break;
		
	case Cell.CELL_TYPE_NUMERIC:
		if(DateUtil.isCellDateFormatted(cell)){
			obj = DateUtil.getJavaDate(cell.getNumericCellValue());
		}else if(Number.class.isAssignableFrom(type) || ClassUtils.isBaseNumberType(type)){
			//當pojo字段類型是數字型時以數字形式獲取
			obj = cell.getNumericCellValue();				
		}else{
			//其他類型都以string獲取
			obj = DATA_FORMATTER.formatCellValue(cell);				
		}
		break;
		
	case Cell.CELL_TYPE_ERROR:
		return null;
	}
	if(fieldInfo.getImportProcessor() != null){
		obj = fieldInfo.getImportProcessor().process(obj);
	}
	obj = ConvertUtils.convertIfNeccesary(obj, type, dateFormat);
	return obj;
}
 
開發者ID:long47964,項目名稱:excel-utils,代碼行數:46,代碼來源:ExcelImportUtil.java

示例8: visitCellValueNumeric

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
@Override
public void visitCellValueNumeric(Column column, Object source, double value) {
	TimestampParser parser = getTimestampParser(column);
	TimeZone tz = parser.getDefaultTimeZone().toTimeZone();
	Date date = DateUtil.getJavaDate(value, tz);
	Timestamp t = Timestamp.ofEpochMilli(date.getTime());
	pageBuilder.setTimestamp(column, t);
}
 
開發者ID:hishidama,項目名稱:embulk-parser-poi_excel,代碼行數:9,代碼來源:TimestampCellVisitor.java

示例9: readCell

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
private static final Object readCell(final Cell cell) {
    switch (cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:
            if (DateUtil.isCellDateFormatted(cell)) {
                return DateUtil.getJavaDate(cell.getNumericCellValue());
            }
            return cell.getNumericCellValue();
        case Cell.CELL_TYPE_BOOLEAN:
            return cell.getBooleanCellValue();
        default:
            return cell.getStringCellValue();
    }
}
 
開發者ID:cardillo,項目名稱:joinery,代碼行數:14,代碼來源:Serialization.java

示例10: parseDateTime

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
public static DateTime parseDateTime(String str) {
	try {
		return DATE_FORMATTER.parseDateTime(str);
	} catch (IllegalArgumentException e) {
		try {
			double n = Double.parseDouble(str);
			return new DateTime(DateUtil.getJavaDate(n));
		} catch (NumberFormatException e2) {
			//Ignore
		}
		throw e;//Rethrow IllegalArgumentException
	}
}
 
開發者ID:shunjikonishi,項目名稱:excel2canvas,代碼行數:14,代碼來源:InputRule.java

示例11: getValue

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
public static Object getValue(Cell cell) {
	Object result = null;
	//タイプ分岐
	switch (cell.getCellType())
	{
		case Cell.CELL_TYPE_BLANK:
			result = "";
			break;
		case Cell.CELL_TYPE_BOOLEAN:
			result = cell.getBooleanCellValue();
			break;
		case Cell.CELL_TYPE_ERROR:
			result = cell.getErrorCellValue();
			break;
		case Cell.CELL_TYPE_FORMULA:
			result = cell.getCellFormula();
			break;
		case Cell.CELL_TYPE_NUMERIC:
			double num = cell.getNumericCellValue();
			if (DateUtil.isCellDateFormatted(cell)) {
				///日付型
				result = DateUtil.getJavaDate(num);
			} else {
				// 數値型
				result = cell.getNumericCellValue();
			}
			break;
		case Cell.CELL_TYPE_STRING:
			result = cell.getStringCellValue();
			break;
	}
	return result;
}
 
開發者ID:yu-ki106f,項目名稱:PoiManager,代碼行數:34,代碼來源:ConvertUtil.java

示例12: getCellDate

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
private static Date getCellDate(Cell cell) {
    if (HSSFDateUtil.isCellDateFormatted(cell)) {// 處理日期格式、時間格式
        return cell.getDateCellValue();
    }
    return DateUtil.getJavaDate(cell.getNumericCellValue());
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:7,代碼來源:CellConvert.java

示例13: addEvent

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
private void addEvent(final Map<String, Serializable> input) {
	if (!this.uniqueEvents.contains(input)) {
		final Map<String, Serializable> values = new HashMap<String, Serializable>();

		for (final TypeTreeNode attribute : this.eventType.getRootLevelValueTypes()) {
			try {
				final String attributeExpression = attribute.getAttributeExpression();
				Serializable attributeValue = null;
				if (input.get(attributeExpression) != null) {
					if (attribute.getType() == AttributeTypeEnum.DATE) {
						if (input.get(attributeExpression) instanceof String) {
							attributeValue = DateUtils.parseDate((String) input.get(attributeExpression));
						} else if (input.get(attributeExpression) instanceof Double) {
							attributeValue = DateUtil.getJavaDate((Double) input.get(attributeExpression));
						} else if (input.get(attributeExpression) instanceof Long) {
							attributeValue = DateUtil.getJavaDate((Long) input.get(attributeExpression));
						} else {
							attributeValue = input.get(attributeExpression);
						}
					} else if (attribute.getType() == AttributeTypeEnum.INTEGER) {
						if (input.get(attributeExpression) instanceof Long) {
							attributeValue = ((Long) input.get(attributeExpression)).longValue();
						} else if (input.get(attributeExpression) instanceof Double) {
							attributeValue = ((Double) input.get(attributeExpression)).longValue();
						} else if (input.get(attributeExpression) instanceof Integer) {
							attributeValue = ((Integer) input.get(attributeExpression)).longValue();
						} else {
							attributeValue = (new Long(((String) input.get(attributeExpression)))).longValue();
						}
					} else if (attribute.getType() == AttributeTypeEnum.FLOAT) {
						if (input.get(attributeExpression) instanceof Long) {
							attributeValue = ((Long) input.get(attributeExpression)).doubleValue();
						} else if (input.get(attributeExpression) instanceof Double) {
							attributeValue = ((Double) input.get(attributeExpression)).doubleValue();
						} else if (input.get(attributeExpression) instanceof Integer) {
							attributeValue = ((Integer) input.get(attributeExpression)).doubleValue();
						} else {
							attributeValue = (new Double(((String) input.get(attributeExpression)))).doubleValue();
						}
					} else {
						attributeValue = input.get(attributeExpression).toString();
					}
				}
				values.put(attributeExpression, attributeValue);
			} catch (final Exception e) {
				e.printStackTrace();
			}
		}

		// System.out.println(values.toString());
		final EapEvent event = new EapEvent(this.eventType, new Date(), values);

		final Object timestamp = input.get(event.getEventType().getTimestampName());
		if (timestamp instanceof Date) {
			event.setTimestamp((Date) timestamp);
		}

		Broker.getEventImporter().importEvent(event);
		// System.out.println("Event created: " + event);
		this.numberOfEventsFired++;
		this.uniqueEvents.add(input);
	}
}
 
開發者ID:bptlab,項目名稱:Unicorn,代碼行數:64,代碼來源:TransformationListener.java

示例14: getDateCellValue

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
public Date getDateCellValue() {
    return DateUtil.getJavaDate(getNumericCellValue());
}
 
開發者ID:DataArt,項目名稱:CalculationEngine,代碼行數:4,代碼來源:PoiWorkbookConverters.java

示例15: createValue

import org.apache.poi.ss.usermodel.DateUtil; //導入方法依賴的package包/類
private String createValue() {
    if (_value.length() == 0) {
        return null;
    }

    switch (_dataType) {

    case BOOL:
        char first = _value.charAt(0);
        return first == '0' ? "false" : "true";
    case ERROR:
        logger.warn("Error-cell occurred: {}", _value);
        return _value.toString();
    case FORMULA:
        return _value.toString();
    case INLINESTR:
        XSSFRichTextString rtsi = new XSSFRichTextString(_value.toString());
        return rtsi.toString();
    case SSTINDEX:
        String sstIndex = _value.toString();
        int idx = Integer.parseInt(sstIndex);
        XSSFRichTextString rtss = new XSSFRichTextString(_sharedStringTable.getEntryAt(idx));
        return rtss.toString();
    case NUMBER:
        final String numberString = _value.toString();
        if (_formatString != null) {
            DataFormatter formatter = getDataFormatter();
            if (HSSFDateUtil.isADateFormat(_formatIndex, _formatString)) {
                Date date = DateUtil.getJavaDate(Double.parseDouble(numberString));
                return DateUtils.createDateFormat().format(date);
            }
            return formatter.formatRawCellContents(Double.parseDouble(numberString), _formatIndex, _formatString);
        } else {
            if (numberString.endsWith(".0")) {
                // xlsx only stores doubles, so integers get ".0" appended
                // to them
                return numberString.substring(0, numberString.length() - 2);
            }
            return numberString;
        }
    default:
        logger.error("Unsupported data type: {}", _dataType);
        return "";
    }
}
 
開發者ID:apache,項目名稱:metamodel,代碼行數:46,代碼來源:XlsxSheetToRowsHandler.java


注:本文中的org.apache.poi.ss.usermodel.DateUtil.getJavaDate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。