Linux练习(获得系统时间)

#include <time.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
        int i;
        time_t the_time;
        for(i=1;i<=5;i++)
        {
            the_time=time((time_t*)0);
            printf("the time is %ld\n",the_time);
            sleep(2);
        
        }
        exit(0);

}

时间是从1970年1月1日开始的。

函数原型:

#include <time.h>

time_t time(time_t *tloc);

原文地址:https://www.cnblogs.com/tiandsp/p/2677429.html