本文摘自PHP中文网,作者藏色散人,侵删。
time()函数的定义时间为time.h (c++中的ctime)头文件。此函数以秒为单位返回自1970年1月1日00:00:00 UTC (Unix时间戳)以来的时间。如果second不是空指针,返回的值也存储在second指向的对象中。
语法:
1 | time_t time( time_t *second )
|
参数:该函数接受单参数second。此参数用于设置存储时间的time_t对象。
返回值:此函数将当前日历时间作为类型为time_t的对象返回。
示例1:
1 2 3 4 5 6 7 8 9 10 11 12 | # include <stdio.h>
# include <time.h>
int main ()
{
time_t seconds;
seconds = time(NULL);
printf( "Seconds since January 1, 1970 = %ld\n" , seconds);
return (0);
}
|
输出:
1 | Seconds since January 1, 1970 = 1538123990
|
示例2:
1 2 3 4 5 6 7 8 9 10 11 12 13 | # include <stdio.h>
# include <time.h>
int main()
{
time_t seconds;
time(&seconds);
printf( "Seconds since January 1, 1970 = %ld\n" , seconds);
return 0;
}
|
输出:
1 | Seconds since January 1, 1970 = 1538123990
|
相关推荐:《C教程》
本篇文章就是关于C中的time()函数的使用方法介绍,希望对需要的朋友有所帮助!
以上就是C中的time()函数怎么用?的详细内容!
相关阅读 >>
c/c++函数如何返回多个值?(代码示例)
在c语言里二维数组在内存中的存放顺序是什么?
c 语言怎么实现三个数大小排序
c语言如何用if判断成绩等级?
c 语言结构体详解
return在c语言中是什么意思?
精选的这19道c/c+面试题,你能答对多少呢? - 个人文章 思否
c语言三目运算符怎么用?
c语言比较三个数大小
c语言中double是什么意思?
更多相关阅读请进入《c》频道 >>
转载请注明出处:木庄网络博客 » C中的time()函数怎么用?