Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/c7a0c22cc0e3648de3c235c5593321f0 to your computer and use it in GitHub Desktop.
Save parzibyte/c7a0c22cc0e3648de3c235c5593321f0 to your computer and use it in GitHub Desktop.
public static String sumarAnios(String fechaYHora, long anios) {
// Crear un formateador como 2018-10-16
DateTimeFormatter formateador = DateTimeFormatter.ofPattern("uuuu-MM-dd");
// Lo convertimos a objeto para poder trabajar con él
LocalDate fechaLocal = LocalDate.parse(fechaYHora, formateador);
// Sumar los años indicados
fechaLocal = fechaLocal.plusYears(anios);
//Formatear de nuevo y regresar como cadena
return fechaLocal.format(formateador);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment