Created
August 7, 2019 18:25
-
-
Save parzibyte/c7a0c22cc0e3648de3c235c5593321f0 to your computer and use it in GitHub Desktop.
Sumar años con Java y LocalDate | https://parzibyte.me/blog/2018/10/16/sumar-restar-fechas-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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