C 库函数 - time()

C++ 教程 · 2019-02-25 21:12:58

描述

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

声明

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

time_t time(time_t *t)

参数

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

返回值

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

实例

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

#include <stdio.h>
#include <time.h>

int main ()
{
  time_t seconds;

  seconds = time(NULL);
  printf("自 1970-01-01 起的小时数 = %ld\n", seconds/3600);
  
  return(0);
}

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

自 1970-01-01 起的小时数 = 373711

点击查看所有 C++ 教程 文章: https://www.codercto.com/courses/l/18.html

查看所有标签

Domain-Driven Design Distilled

Domain-Driven Design Distilled

Vaughn Vernon / Addison-Wesley Professional / 2016-6-2 / USD 36.99

Domain-Driven Design (DDD) software modeling delivers powerful results in practice, not just in theory, which is why developers worldwide are rapidly moving to adopt it. Now, for the first time, there......一起来看看 《Domain-Driven Design Distilled》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

MD5 加密
MD5 加密

MD5 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具