方法一

    1. time_t seconds;
    2. seconds = time((time_t *)NULL);/获取秒
    3. 打印seconds如下
    4. 1104556407
    5. 1104556408
    6. 1104556409
    7. 1104556410
    8. 1104556411

    方法二:

    1. time_t now;
    2. struct tm *tm_now;
    3. time(&now);
    4. tm_now = localtime(&now);

    tm的范围就是0~60。
    方法三打印当前时间

    time_t t;
        struct tm *p;
    
        t=time(NULL);
        p=localtime(&t);
        printf("%s\n", asctime(p));
    

    方法四:

    struct timeval tv;        
    gettimeofday(&tv, NULL);
    
    printf("tv_sec: %d\n", tv.tv_sec);
    printf("tv_usec: %d\n", tv.tv_usec);