Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. public static String sumarAnios(String fechaYHora, long anios) {
  2. // Crear un formateador como 2018-10-16 15:00:00
  3. DateTimeFormatter formateador = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
  4.  
  5. // Lo convertimos a objeto para poder trabajar con él
  6. LocalDateTime fechaYHoraLocal = LocalDateTime.parse(fechaYHora, formateador);
  7.  
  8. // Sumar los años indicados
  9. fechaYHoraLocal = fechaYHoraLocal.plusYears(anios);
  10.  
  11. //Formatear de nuevo y regresar como cadena
  12. return fechaYHoraLocal.format(formateador);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement