_mkgmtime, _mkgmtime32, _mkgmtime64

Convierte una hora UTC representada por un struct tm en una hora UTC representada por un tipo time_t.

Sintaxis

time_t _mkgmtime(
   struct tm* timeptr
);
__time32_t _mkgmtime32(
   struct tm* timeptr
);
__time64_t _mkgmtime64(
   struct tm* timeptr
);

Parámetros

timeptr
Puntero a la hora UTC como struct tm que se debe convertir.

Valor devuelto

Cantidad de tipo __time32_t o __time64_t que representa el número de segundos transcurridos desde la medianoche del 1 de enero de 1970, hora universal coordinada (UTC). Si la fecha está fuera del intervalo (vea la sección Comentarios) o la entrada no se puede interpretar como una hora válida, el valor devuelto será -1.

Comentarios

Las funciones _mkgmtime32 y _mkgmtime64 convierten una hora UTC en un tipo __time32_t o __time64_t que representa la hora con el formato UTC. Para convertir una hora local en hora UTC, use mktime, _mktime32 y _mktime64.

_mkgmtime es una función insertada que se evalúa como _mkgmtime64 y time_t es equivalente a __time64_t. Si necesita forzar el compilador para interpretar time_t como el antiguo time_tde 32 bits, puede definir _USE_32BIT_TIME_T. No se recomienda, ya que la aplicación puede producir un error después del 18 de enero de 2038, el intervalo máximo de un valor time_t de 32 bits. No se permite en las plataformas de 64 bits.

La estructura de tiempo que se haya pasado cambia del siguiente modo, de la misma manera en que cambia con las funciones _mktime: los campos tm_wday y tm_yday se establecen en valores nuevos basados en los valores de tm_mday y tm_year. Dado que se supone que la hora es UTC, se omite el campo tm_isdst.

El intervalo de la función _mkgmtime32 va desde la medianoche del 1 de enero de 1970 (hora UTC) hasta las 23:59:59 del 18 de enero de 2038 (hora UTC). El intervalo de _mkgmtime64 va desde la medianoche del 1 de enero de 1970 (hora UTC) hasta las 23:59:59 del 31 de diciembre de 3000 (hora UTC). Una fecha que está fuera del intervalo da como resultado un valor devuelto de -1. El intervalo de _mkgmtime depende de si _USE_32BIT_TIME_T está definido. Cuando no se define, que es la opción predeterminada, el intervalo es el mismo que _mkgmtime64. De lo contrario, el intervalo está limitado al intervalo de 32 bits de _mkgmtime32.

Tanto gmtime como localtime usan un búfer estático común para la conversión. Si proporciona este búfer a _mkgmtime, se destruye el contenido anterior.

Ejemplos

// crt_mkgmtime.c
#include <stdio.h>
#include <time.h>

int main()
{
    struct tm t1, t2;
    time_t now, mytime, gmtime;
    char buff[30];

    time( & now );

    _localtime64_s( &t1, &now );
    _gmtime64_s( &t2, &now );

    mytime = mktime(&t1);
    gmtime = _mkgmtime(&t2);

    printf("Seconds since midnight, January 1, 1970\n");
    printf("My time: %I64d\nGM time (UTC): %I64d\n\n", mytime, gmtime);

    /* Use asctime_s to display these times. */

    _localtime64_s( &t1, &mytime );
    asctime_s( buff, sizeof(buff), &t1 );
    printf( "Local Time: %s\n", buff );

    _gmtime64_s( &t2, &gmtime );
    asctime_s( buff, sizeof(buff), &t2 );
    printf( "Greenwich Mean Time: %s\n", buff );

}
Seconds since midnight, January 1, 1970
My time: 1171588492
GM time (UTC): 1171588492

Local Time: Thu Feb 15 17:14:52 2007

Greenwich Mean Time: Fri Feb 16 01:14:52 2007

En el ejemplo siguiente se muestra cómo _mkgmtime rellena la estructura incompleta. Calcula los valores del día de la semana y del año.

// crt_mkgmtime2.c
#include <stdio.h>
#include <time.h>
#include <memory.h>

int main()
{
    struct tm t1, t2;
    time_t gmtime;
    char buff[30];

    memset(&t1, 0, sizeof(struct tm));
    memset(&t2, 0, sizeof(struct tm));

    t1.tm_mon = 1;
    t1.tm_isdst = 0;
    t1.tm_year = 103;
    t1.tm_mday = 12;

    // The day of the week and year will be incorrect in the output here.
    asctime_s( buff, sizeof(buff), &t1);
    printf("Before calling _mkgmtime, t1 = %s t.tm_yday = %d\n",
            buff, t1.tm_yday );

    gmtime = _mkgmtime(&t1);

    // The correct day of the week and year were determined.
    asctime_s( buff, sizeof(buff), &t1);
    printf("After calling _mkgmtime, t1 = %s t.tm_yday = %d\n",
            buff, t1.tm_yday );

}
Before calling _mkgmtime, t1 = Sun Feb 12 00:00:00 2003
t.tm_yday = 0
After calling _mkgmtime, t1 = Wed Feb 12 00:00:00 2003
t.tm_yday = 42

Consulte también

Administración de tiempo
asctime, _wasctime
asctime_s, _wasctime_s
gmtime, _gmtime32, _gmtime64
gmtime_s, _gmtime32_s, _gmtime64_s
localtime_s, _localtime32_s, _localtime64_s
mktime, _mktime32, _mktime64
time, _time32, _time64