|
time 函数文档
函数摘要:
time 函数用于返回从标准计时点到当前时间的秒数,即从 1970 年 1 月 1 日的 UTC 时间 0 时 0 分 0 秒算起到现在所经过的秒数。
函数原型:
小甲鱼温馨提示:time_t 事实上是一个 32 位的整型变量。
- #include <time.h>
- ...
- time_t time(time_t *t);
[color=rgb(51, 102, 153) !important]复制代码
参数解析:
参数 | 含义 | time_t | 1. 一个指向 time_t 类型变量的指针,用于存放获得的结果
2. 可以将该参数指定为 NULL,通过函数的返回值获得结果 |
返回值:
如果函数调用成功,返回值是标准计时点到当前时间所经过的秒数;
如果函数调用失败,返回值是 -1,并设置 errno。
演示:
- #include <stdio.h>
- #include <time.h>
- int main(void)
- {
- time_t seconds;
- // 下面语句也可以写成:time(&seconds);
- seconds = time(NULL);
- printf("1970年1月1日零点到现在经过了%ld个小时!\n", seconds / 3600);
- return 0;
- }
[color=rgb(51, 102, 153) !important]复制代码
|
|