Handling dates

0

I have questions about the steps to manipulate dates.

Are the steps below ok? Can I start my studies?

  • I have the Date attribute and want to insert 2 days.
  • Convert Date to String .
  • Convert String to Calendar .
  • I make the code to manipulate the date obtained.
  • Converting from Calendar to String .
  • Converting from String to Date .
  • Saved.

Why should I try to declare as Calendar when saved from this error?

  Unresolved compilation problem: Type mismatch: can not convert from

Code for more details:

// data em que o dinheiro foi entregue
    @DateTimeFormat(pattern = "dd/MM/yyyy")
    @Temporal(TemporalType.DATE)
    private Date dataEmprestimo;

If I put private Calendar dataEmprestimo , it gives the error mentioned above.

    
asked by anonymous 02.06.2017 / 00:17

1 answer

1

Can use the Java 8 API is easier to handle dates

import java.time.LocalDate;
LocalDate dataInicio;
@JsonFormat(pattern = "yyyy-MM-dd")
LocalDate data;

On your object just retrieve the LocalDate field and run

 objeto.getData().plusDays(1) 

// Add a day

    
02.06.2017 / 01:31