-
-
Save parzibyte/74955c3e95e317b087e3f6d61b5dd4e4 to your computer and use it in GitHub Desktop.
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
/** | |
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