How to create getter from Local Date variable?

Asked

Viewed 180 times

1

I have a class called Hospede, where I have the method getData_entrada(), that returns a variable LocalDate(new java8 API). However, when I try to capture this method, it always returns to me 'null'.

Detail: when I try to capture the other getters works normally.

//conteudo getData_entrada:

public LocalDate getData_entrada() {

        return data_entrada;
   }



     Hospede hospede = (Hospede) mStrings.get(position);

     textView_nome.setText(hospede.getNome());

     LocalDate data_Entrada = hospede.getData_entrada();
  • Is there any way you can put the contents of getData_entrada() in the question?

  • public date getData_input() { Return data_input; }

  • There are several ways to solve this problem, explain us better the context of your application so that we can help you with the best option.

1 answer

2

You can define the getData_entrada() thus below:

public LocalDate getData_entrada() {
    return LocalDate.now();
}

View static methods of the public class LocalDate to obtain the current time:

  • now(): Get the current system clock date in the standard time zone.
  • now(clock clock): Get the current date of the specified clock.
  • now(Zoneid zone): Get the current system clock date in the specified time zone.

See more details in the documentation.

Browser other questions tagged

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