Error getting time with row.getCell ()

-1

I'm getting data from a worksheet in excel.

public void Hora()
    Cell horaAgen = null;

    if(row.getCell(7) != null ){
        horaAgen = row.getCell(7);
        System.out.println("hora: "+horaAgen);
   }

}

In the worksheet this: 9:00:00 After reading I get: 31-Dec-1899

What functions should I use to get the correct time.

Note:

  • the date I get correctly dd / mm / yyyy
  • I'm using apache poi
  • What data format is being used in the table: Time
  • Should I convert the obtained time to string
  • asked by anonymous 03.10.2018 / 20:18

    1 answer

    0

    The solution to this problem was this:

    public void obterHora(){
        String hora;
        int h=row.getCell(7).getDateCellValue().getHours();
        int m=row.getCell(7).getDateCellValue().getMinutes();
        int s=row.getCell(7).getDateCellValue().getSeconds();
    
        hora = h+":"+m+":"+s;
    
        SimpleDateFormat formatador = new SimpleDateFormat("HH:mm:ss");
        Date data = formatador.parse(horario);
        horaAgen = new Time(data.getTime());
    
        System.out.println("hora: "+horaAgen);
    }
    

    Result:

      

    9:00 AM   12:00 PM

    Always in format

      

    HH: mm: ss

    This way you have met my needs

        
    05.10.2018 / 16:53