Está en la página 1de 1

#include <stdio.

h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define LONG_CADENA 128
int main(void)
{
time_t fecha;
struct tm *temp;
struct tm fecha_tm;
char salida[LONG_CADENA];

/* obtener fecha (time_t) */
if ((fecha = time(NULL)) == (time_t) -1)
return EXIT_FAILURE;

/* obtener fecha (struct tm) */
temp = localtime(&fecha);
memcpy(&fecha_tm, temp, sizeof fecha_tm);

/* imprimir mediante las funciones de la biblioteca time.h */
printf("%s", ctime(&fecha));
strftime(salida, LONG_CADENA, "%a %b %d %H:%M:%S %Y\n", &fecha_tm);
printf("%s", salida);

/* imprimir manualmente */
printf(" %02d %02d:", fecha_tm.tm_mday, fecha_tm.tm_hour);
printf("%02d:%02d ", fecha_tm.tm_min, fecha_tm.tm_sec);
printf("%d\n", fecha_tm.tm_year + 1900);

return EXIT_SUCCESS;
}

También podría gustarte