std::time
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <ctime> 中定义
|
||
time_t time( std::time_t *time ); |
||
返回一个std::time_t对象编码为当前日历时间.
原文:
Returns the current calendar time encoded as a std::time_t object.
目录 |
[编辑] 参数
time | - | 指针到一个std::time_t对象或NULL存储时间
原文: pointer to a std::time_t object to store the time in or NULL |
[编辑] 返回值
当前日历时间编码的为成功,std::time_t错误(std::time_t)(-1)对象。如果参数是不NULL,返回值也设置为指向的对象的
time
.原文:
Current calendar time encoded as std::time_t object on success, (std::time_t)(-1) on error. If the argument is not NULL, the return value is also set to the object pointed by
time
.[编辑] 注释
日历时间的编码std::time_t是不确定的,但大多数系统符合POSIX specification和返回值的纪元以来的秒数的整数类型。实现std::time_t是一个32位有符号整数(许多历史实现)未能在2038年.
原文:
The encoding of calendar time in std::time_t is unspecified, but most systems conform to POSIX specification and return a value of integral type holding the number of seconds since the Epoch. Implementations in which std::time_t is a 32-bit signed integer (many historical implementations) fail in the year 2038.
[编辑] 示例
#include <ctime> #include <iostream> int main() { std::time_t result = std::time(NULL); std::cout << std::asctime(std::localtime(&result)) << result << " seconds since the Epoch\n"; }
输出:
Wed Sep 21 10:27:52 2011 1316615272 seconds since the Epoch
[编辑] 另请参阅
因为时代的日历时间转换时间为本地时间表示 原文: converts time since epoch to calendar time expressed as local time (函数) | |
转换的时间,因为时代的日历时间为协调世界时表示 原文: converts time since epoch to calendar time expressed as Universal Coordinated Time (函数) | |
(C++11) |
从系统获取的实时时钟 原文: wall clock time from the system-wide realtime clock (类) |
C documentation for time
|