Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active February 9, 2019 05:56
Show Gist options
  • Save parzibyte/74955c3e95e317b087e3f6d61b5dd4e4 to your computer and use it in GitHub Desktop.
Save parzibyte/74955c3e95e317b087e3f6d61b5dd4e4 to your computer and use it in GitHub Desktop.
/**
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