Error obtaining time with Row.getCell()

Asked

Viewed 49 times

-1

I’m getting data from a spreadsheet in excel.

public void Hora()
    Cell horaAgen = null;

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

}

On the spreadsheet this: 9:00:00 After being read get: 31-dec-1899

What functions should I use to get the right time.

Observing:

  1. date can get dd/mm/yyyy correctly
  2. I’m using apache poi
  3. What data format is being used in the table: Time
  4. Must convert the obtained time to string
  • The question lacks information. What type of variable is being used? What data format is being used in the table? This article might help: http://blog.alura.com.br/como-converter-string-para-date-java/

  • What type of variable is being used: Cell

  • What data format is being used in the table: time

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.