#include <time.h> #include <sys/time.h> void sysLocalTime(char *str_info) { time_t timesec; struct tm *p; time(×ec); p = localtime(×ec); printf("%d%d%d - %d:%2d:%d %s ", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, str_info); } void sysUsecTime() { struct timeval tv; struct timezone tz; struct tm *p; gettimeofday(&tv, &tz); printf("tv_sec:%ld ",tv.tv_sec); printf("tv_usec:%ld ",tv.tv_usec); printf("tz_minuteswest:%d ",tz.tz_minuteswest); printf("tz_dsttime:%d ",tz.tz_dsttime); p = localtime(&tv.tv_sec); printf("time_now:%d%d%d%d%d%d.%ld ", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec); } int main(void) { char *str_info="xxxxxxxxxxxxxxx"; sysLocalTime(str_info); printf("============gettimeofday============== "); sysUsecTime(); return 0; }