dev/c/timeconv_test/timeconv_test.c
2011-12-07 18:42:08 +03:00

49 lines
674 B
C

#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "timeconv.h"
void usec_test()
{
struct tm t;
struct timeval tv;
uint64_t usec = 0;
char buf[256];
putenv("TZ=GMT+0");
t.tm_sec = 1;
t.tm_min = 2;
t.tm_hour = 3;
t.tm_mday = 4;
t.tm_mon = 5-1;
t.tm_year = 2011-1900;
t.tm_isdst = 0;
tv.tv_sec = mktime(&t);
tv.tv_usec = 798431;
usec = usec_from_timeval(tv);
memset(&tv, 0, sizeof(tv));
tv = timeval_from_usec(usec);
memset(&t, 0, sizeof(t));
t = *gmtime(&tv.tv_sec);
strftime(buf, sizeof(buf), "%Y.%m.%d %H:%M:%S", &t);
printf("%s\n", buf);
}
int main(int argc, char *argv[])
{
usec_test();
return 0;
}