Namespaces
Variants

Standard library header <time.h>

From cppreference.net

Este encabezado es parte de la biblioteca de utilidades de fecha y hora .

Contenidos

Funciones

Manipulación del tiempo
calcula la diferencia entre tiempos
(función)
devuelve el tiempo calendario actual del sistema como tiempo desde la época
(función)
devuelve el tiempo de reloj del procesador en bruto desde que se inicia el programa
(función)
devuelve el tiempo calendario en segundos y nanosegundos basado en una base de tiempo dada
(función)
devuelve la resolución del tiempo calendario basado en una base de tiempo dada
(función)
Conversiones de formato
(obsoleto en C23) (C11)
convierte un objeto tm a una representación textual
(función)
(obsoleto en C23) (C11)
convierte un objeto time_t a una representación textual
(función)
convierte un objeto tm a una representación textual personalizada
(función)
convierte el tiempo desde la época a tiempo calendario expresado como Tiempo Universal Coordinado (UTC)
(función)
convierte el tiempo desde la época a tiempo calendario expresado como hora local
(función)
convierte el tiempo calendario a tiempo desde la época
(función)

Constantes

número de ticks del reloj del procesador por segundo
(constante macro)

Tipos

tipo de tiempo calendario
(struct)
tipo de tiempo calendario desde época
(typedef)
tipo de tiempo de procesador desde era
(typedef)
tiempo en segundos y nanosegundos
(struct)

Sinopsis

#define __STDC_VERSION_TIME_H__ 202311L
#define NULL           /* ver descripción */
#define CLOCKS_PER_SEC /* ver descripción */
#define TIME_UTC       /* ver descripción */
typedef /* ver descripción */ clock_t;
typedef /* ver descripción */ size_t;
typedef /* ver descripción */ time_t;
struct timespec { /* ver descripción */ };
struct tm { /* ver descripción */ };
clock_t clock(void);
double difftime(time_t time1, time_t time0);
time_t mktime(struct tm* timeptr);
time_t timegm(struct tm* timeptr);
time_t time(time_t* timer);
int timespec_get(struct timespec* ts, int base);
int timespec_getres(struct timespec* ts, int base);
[[deprecated]] char* asctime(const struct tm* timeptr);
[[deprecated]] char* ctime(const time_t* timer);
struct tm* gmtime(const time_t* timer);
struct tm* gmtime_r(const time_t* timer, struct tm* buf);
struct tm* localtime(const time_t* timer);
struct tm* localtime_r(const time_t* timer, struct tm* buf);
size_t strftime(char* restrict s, size_t maxsize, const char* restrict format,
const struct tm* restrict timeptr);

Solo si es compatible con la implementación:

#define TIME_MONOTONIC /* ver descripción */
#define TIME_ACTIVE    /* ver descripción */

Solo si los hilos son compatibles y está soportado por la implementación:

#define TIME_THREAD_ACTIVE /* ver descripción */

Solo si la implementación define __STDC_LIB_EXT1__ y adicionalmente el código de usuario define __STDC_WANT_LIB_EXT1__ antes de cualquier inclusión de <time.h> :

#ifdef __STDC_WANT_LIB_EXT1__
typedef /* ver descripción */ errno_t;
typedef /* ver descripción */ rsize_t;
errno_t asctime_s(char* s, rsize_t maxsize, const struct tm* timeptr);
errno_t ctime_s(char* s, rsize_t maxsize, const time_t* timer);
struct tm* gmtime_s(const time_t* restrict timer, struct tm* restrict result);
struct tm* localtime_s(const time_t* restrict timer, struct tm* restrict result);
#endif