函数名: time
头文件:
函数原型: long time(long *t);
功 能: 获取系统时间
参数: 为当前时间
返回值: 返回当前系统时间
补充:
(1) t1=time(NULL)或t1=time(0)
将空指针传递给time()函数,并将time()返回值赋给变量t1
(2) time(&t2);
将变量t2的地址作为实参传递给time()函数,函数自动把结果传递给t2,不需要额外的赋值语句
程序例: 获取系统时间,并输出结果
#include
#include
int main(void){
time_t t;
t = time(NULL);
printf("The number of seconds since January 1, 1970 is %ld\n",t);
return 0;
}运行结果:
The number of seconds since January 1, 1970 is 1592304422