C 库函数 - time()

描述

C 库函数 time_t time(time_t *seconds) 返回自纪元 Epoch(1970-01-01 00:00:00 UTC)起经过的时间,以秒为单位。如果 seconds 不为空,则返回值也存储在变量 seconds 中。

声明

下面是 time() 函数的声明。

cpp 复制代码
time_t time(time_t *seconds)

参数

seconds -- 这是指向类型为 time_t 的对象的指针,用来存储 seconds 的值。

返回值

以 time_t 对象返回当前日历时间。

实例

下面的实例演示了 time() 函数的用法。

cpp 复制代码
#include <stdio.h>
#include <time.h>
 
int main ()
{
  time_t seconds;
 
  seconds = time(NULL);
  printf("自 1970-01-01 起的小时数 = %ld\n", seconds/3600);
  
  return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

cpp 复制代码
自 1970-01-01 起的小时数 = 373711
相关推荐
CodeYp20191 分钟前
第19讲:封装红黑树实现 mymap 和 myset
开发语言·c++·红黑树
简单电磁炮10 分钟前
关于can的调试
c语言·stm32·单片机
超级架构师1 小时前
让 COBOL 长出 AI 大脑:原生 Agent 核心框架 praxo-core 深度剖析
c语言·开发语言·c++·人工智能·python·架构·ai编程
·present·1 小时前
CSAPP(lecture 10)
c语言·c++
Non-existent9871 小时前
在 WPS/Excel 里做地理数据处理:功能市场 + 奥维 / Google Earth / QGIS 三种跳转实战
开发语言·javascript·ecmascript
xiaolang_8616_wjl1 小时前
c++游戏_宝可梦大世界(源代码)
开发语言·c++·游戏
Leinwin2 小时前
Copilot Studio 实战:多模型选择、GitHub Copilot harness 计费与 Copilot Credits 额度管理
开发语言·c#
余额瞒着我当琳2 小时前
C++异常,异常的概念,异常抛出与捕获,RAII 和智能指针的设计思路,C++标准库一些指针的使用
java·开发语言·c++·算法
严谨的麻辣烫2 小时前
固定 IP 稳定性如何检测?使用 Python 实现网络连通性与耗时监控
开发语言·数据库·php