Get the time in from an excell worksheet

0

I'm using the POI api in Java. To get the time in an excel spreadsheet. In the excell spreadsheet the data is as text

Image :

publicvoidobterHora(){Cellhora=row.getCell(7);System.out.println("hora: "+hora);
}
  

result: Dec 31, 1899

During the debug you get this data:

    
asked by anonymous 05.10.2018 / 15:40

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:52