Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active Feb 9, 2019
Embed
What would you like to do?
/**
Obtener fecha y hora actual en Java con DateTimeFormatter
y LocalDateTime
@author parzibyte
*/
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
class Main {
public static void main(String[] args) {
String fechaYHora = obtenerFechaYHoraActual();
System.out.println("La fecha y hora es: " + fechaYHora);
}
public static String obtenerFechaYHoraActual() {
String formato = "yyyy-MM-dd HH:mm:ss";
DateTimeFormatter formateador = DateTimeFormatter.ofPattern(formato);
LocalDateTime ahora = LocalDateTime.now();
return formateador.format(ahora);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment