I am trying to read a date column and a time column from a spreadsheet. I am able to retireve the date column from the sheet, but not the time column.
For example, my sheet will have rows of the form:
date time
11/2/2012 12:15:01
I have the following code to get the date column:
while(cellIterator.hasNext()) {
HSSFCell cell = (HSSFCell)cellIterator.next();
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = cell.getCellStyle();
if (HSSFDateUtil.isCellDateFormatted(cell))
{
d = (Date)getDateValue(cell);
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(dateFormat.format(d));
}
}
}
protected static Object getDateValue(HSSFCell cellDate)
{
double numericDateValue = cellDate.getNumericCellValue();
Date date = HSSFDateUtil.getJavaDate(numericDateValue);
return date;
}
As you can see I use
HSSFDateUtil.isCellDateFormatted(cell)
to check if the cell has date value in it. I want to know if i can check if cell has time value using any function.
The excel sheet is coming from an external source. So,i will not be able to make any modifications to the format of it.
Right now, i get the correct date values for date columns. But, for time columns, i am getting
12/31/1899
as result for all rows
See Question&Answers more detail:os