dev/c/time_t_2038/gmtime.c

41 lines
585 B
C

#define _XOPEN_SOURCE
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
struct tm t, *tp = NULL;
time_t tt;
char outstr[200];
putenv("TZ=Europe/Moscow");
t.tm_sec = 1;
t.tm_min = 2;
t.tm_hour = 3;
t.tm_mday = 4;
t.tm_mon = 5;
t.tm_year = 1000;
t.tm_isdst = 0;
tt = mktime(&t);
tp = gmtime(&tt);
if (strftime(outstr, sizeof(outstr), "%Y.%m.%d", tp) != 0)
printf("%s\n", outstr);
printf("%d\n", sizeof(time_t));
printf("%lu\n", tt);
printf("%d\n", sizeof(struct tm));
printf("%s\n", asctime(tp));
return 0;
}