首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::time

Defined in header <ctime>

std::time_t time( std::time_t* arg );

返回当前日历时间,该时间编码为std::time_t对象,并将其存储在arg,除非arg为空指针。

参数

arg

-

pointer to a std::time_t object to store the time, or a null pointer

返回值

当前日历时间编码为std::time_t反对成功,(std::time_t)(-1)关于错误。如果arg,则返回值也存储在arg...

注记

日历时间的编码std::time_t未指定,但大多数系统都符合POSIX规范并返回一个整数类型的值,该值包含自时代.在下列情况下std::time_t是一个32位有符号整数%28许多历史实现%29在2038年失败.

二次

代码语言:javascript
复制
#include <ctime>
#include <iostream>
 
int main()
{
    std::time_t result = std::time(nullptr);
    std::cout << std::asctime(std::localtime(&result))
              << result << " seconds since the Epoch\n";
}

二次

产出:

二次

代码语言:javascript
复制
Wed Sep 21 10:27:52 2011
1316615272 seconds since the Epoch

二次

另见

localtime

converts time since epoch to calendar time expressed as local time (function)

gmtime

converts time since epoch to calendar time expressed as Universal Coordinated Time (function)

system_clock (C++11)

wall clock time from the system-wide realtime clock (class)

c时间文件

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券