#include <stdio.h> #include <time.h> #include <sys/time.h>
int main() { struct timeval tv; struct tm* tm; time_t now;
gettimeofday(&tv, NULL); now = time(NULL);
tm = localtime(&now); printf("%d, %d\n", (int)tv.tv_sec, (int)now); printf("%d-%d-%d %d:%d:%d\n",1900+tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); return 0; }
|
在不用设置时区的情况下gettimeofday和time是一样的...
localtime将time_t转换了struct tm结构...
对于结构体可以man gettimeofday localtime
阅读(1498) | 评论(0) | 转发(0) |