std::mktime
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <ctime> 中定义
|
||
std::time_t mktime( std::tm* time ); |
||
本地日历时间转换成一个划时代的时间,因为作为std::time_t对象,而忽略
time->tm_wday
和time->yday
的值。其他组件time
的值并不限于其通常范围。负值的time->tm_isdst
导致mktime
如果夏令时在试图确定.原文:
Converts local calendar time to a time since epoch as a std::time_t object, ignoring the values of
time->tm_wday
and time->yday
. The values of other components of time
are not restricted to their usual ranges. A negative value of time->tm_isdst
causes mktime
to attempt to determine if Daylight Saving Time was in effect.如果成功的话,会重新计算并更新中的所有字段
time
,以满足他们适当的范围内.原文:
If successful, recalculates and updates all fields in
time
to fit their proper ranges.目录 |
[编辑] 参数
time | - | 指针指定本地日历的时间来转换到std::tm对象
原文: pointer to a std::tm object specifying local calendar time to convert |
[编辑] 返回值
因为时代的成功或std::time_t-1不能表示为一个
time
对象作为std::time_t对象的时间.原文:
Time since epoch as a std::time_t object on success or -1 if
time
cannot be represented as a std::time_t object.[编辑] 示例
显示100个月前的时间
#include <iostream> #include <iomanip> #include <ctime> int main() { std::time_t t = std::time(NULL); std::tm tm = *std::localtime(&t); std::cout << "Today is " << std::put_time(&tm, "%c %Z") <<'\n'; tm.tm_mon -= 100; std::mktime(&tm); std::cout << "100 months ago was " << std::put_time(&tm, "%c %Z") << '\n'; }
输出:
Today is Wed Dec 28 09:56:10 2011 EST 100 months ago was Thu Aug 28 10:56:10 2003 EDT
[编辑] 另请参阅
因为时代的日历时间转换时间为本地时间表示 原文: converts time since epoch to calendar time expressed as local time (函数) | |
C documentation for mktime
|