TIMEGM

Section: Manuel du programmeur Linux (3)
Updated: 21 juillet 2003
Index


NOM
SYNOPSIS
DESCRIPTION
NOTES
VOIR AUSSI
TRADUCTION

NOM

timegm, timelocal - Fonctions réciproques de gmtime and localtime.

SYNOPSIS

#include <time.h>

time_t timelocal (struct tm *tm);

time_t timegm (struct tm *tm);

DESCRIPTION

Les fonctions timelocal() et timegm() sont les réciproques de localtime(3) et gmtime(3).

NOTES

Ces fonctions sont des extensions GNU. La fonction timelocal() est équivalente à la fonction standard POSIX mktime(3). Il n'y a aucune raison de l'utiliser.
Afin d'obtenir une version portable de timegm(), positionnez la variable d'environnement TZ à UTC, appelez mktime() et restaurez la valeur de TZ. Soit un code similaire à
#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;
}

VOIR AUSSI

gmtime(3), localtime(3), mktime(3), tzset(3)

TRADUCTION

Stéphan Rafin, 2002.