date format to string in java with apache from excel

4

I have to read the format of a cell with date to String, it works fine but the year is strange, I attach part of the code and what it shows:

case Cell.CELL_TYPE_NUMERIC:
                    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
           String  s =  sdf.format(cell.getDateCellValue());

                   if(DateUtil.isCellDateFormatted(cell)){
                       System.out.print(s);
            }
           System.out.print(cell.getNumericCellValue());         
                    break;

Show the following: if my date is: 01/03/1994 per screen: 01/03/199434394.0

    
asked by sebastian 28.09.2016 в 04:54
source

1 answer

1

This is because just after the date you print the numeric value of the cell, and in Excel the dates are represented as floating-point numbers.

I think that's how you'll see it clearer:

case Cell.CELL_TYPE_NUMERIC:
    if(DateUtil.isCellDateFormatted(cell)){
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        String  s =  sdf.format(cell.getDateCellValue());
        System.out.println("fecha: " + s);
    } else {
        System.out.println(cell.getNumericCellValue());         
    }
    break;
    
answered by 28.09.2016 / 05:03
source