Dotcpp  >  编程教程  >  time.h头文件  >  C语言time()函数:获取系统时间

C语言time()函数:获取系统时间

点击打开在线编译器,边学边练

函数名: time

头文件:<time.h>

函数原型: long time(long *t);

功 能: 获取系统时间

参数: 为当前时间

返回值: 返回当前系统时间

补充

   (1) t1=time(NULL)或t1=time(0)

      将空指针传递给time()函数,并将time()返回值赋给变量t1

   (2) time(&t2);

      将变量t2的地址作为实参传递给time()函数,函数自动把结果传递给t2,不需要额外的赋值语句 


程序例:  获取系统时间,并输出结果

#include<stdio.h>

#include<time.h> 

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



本文固定URL:https://www.dotcpp.com/course/574

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)