0

Estoy tratando de obtener la fecha actual con el siguiente comando

time_t fecha=time(NULL);
asctime(localtime(&fecha))

Y me la muestra así: Mon Oct 24 20:36:55 2022

¿Hay alguna otra manera de obtener la fecha en formato dd/mm/yyyy? Por ejemplo: 24/10/2022 20:36:55. Gracias de antemano.

1 respuesta 1

1

Según explica el autor de esta respuesta, tendrías que utilizar la función strftime() para poder modificar el formato que te trae el localtime, tu código sería el siguiente:

#include <stdio.h>
#include <time.h>

int main()
{
    time_t fecha = time(NULL);
    char buffer[26];
    struct tm* tm_info;

    tm_info = localtime(&fecha);

    strftime(buffer, 26, "%d/%m/%Y", tm_info);
    puts(buffer);
 
    return 0;
}

Output:

// 26/10/2022
1
  • 1
    Muy claro, muchas gracias!
    – Guy
    el 28 oct. 2022 a las 23:49

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.