Get the time on from an Excell spreadsheet

Asked

Viewed 50 times

0

I am using the POI api in Java. To get the time in an excel spreadsheet. In the Excell worksheet the given is as text

image: inserir a descrição da imagem aqui

public void obterHora(){
    Cell hora = row.getCell(7);
    System.out.println("hora: "+hora);
}

Result: 31-Dec-1899

During debug get this data: inserir a descrição da imagem aqui

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);
}

Upshot:

9:00:00 12:00:00

always in the format

HH:mm:ss

That way you met my needs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.