timelocal(3) funciones inversas para gmtime y localtime

Other Alias

timegm

SINOPSIS

#include <time.h>


time_t timelocal (struct tm *tm);

time_t timegm (struct tm *tm);

DESCRIPCIÓN

Las funciones timelocal() y timegm() son las inversas de localtime(3) y gmtime(3).

OBSERVACIONES

Estas funciones son extensiones de GNU. La función timelocal() es equivalente a la función del estándar POSIX mktime(3). No hay razón para usarla.

Para obtener una versión portable de timegm(), asigne a la variable de entorno TZ el valor UTC, llame a mktime() y restablezca el valor de TZ. Algo así como

#include <time.h>
#include <stdlib.h>
time_t my_timegm (struct tm *tm) {
    time_t ret;
    char *tz;
    tz = getenv("TZ");
    setenv("TZ", "", 1);
    tzset();
    ret = mktime(tm);
    if (tz)
        setenv("TZ", tz, 1);
    else
        unsetenv("TZ");
    tzset();
    return ret;
}