C中的time

C中的time,第1张

C中的time()函数怎么用? time()函数的定义时间为time.h (c++中的ctime)头文件。此函数以秒为单位返回自1970年1月1日00:00:00 UTC (Unix时间戳)以来的时间。如果second不是空指针,返回的值也存储在second指向的对象中。

语法:

time_t time( time_t *second )

参数:该函数接受单参数second。此参数用于设置存储时间的time_t对象。

返回值:此函数将当前日历时间作为类型为time_t的对象返回。

示例1:

#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); 
}

输出:

Seconds since January 1, 1970 = 1538123990

示例2:

#include <stdio.h> 
#include <time.h> 
   
int main() 
{ 
    time_t seconds; 
   
     // 存储时间秒
    time(&seconds); 
    printf("Seconds since January 1, 1970 = %ld\n", seconds); 
   
    return 0; 
}

输出:

Seconds since January 1, 1970 = 1538123990

相关推荐:《C教程》

本篇文章就是关于C中的time()函数的使用方法介绍,希望对需要的朋友有所帮助!

以上就是C中的time()函数怎么用?的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/686317.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-21
下一篇 2022-04-21

发表评论

登录后才能评论

评论列表(0条)

保存