Difference between revisions of "cpp/chrono/c/mktime"
From cppreference.com
m (r2.7.3) (Robot: Adding de, es, it, pt, ru) |
(improve) |
||
Line 5: | Line 5: | ||
}} | }} | ||
− | Converts local calendar time to a time since epoch as a {{c| | + | Converts local calendar time to a time since epoch as a {{c|time_t}} object. {{tt|time->tm_wday}} and {{tt|time->tm_yday}} are ignored. |
− | If successful, | + | A negative value of {{tt|time->tm_isdst}} causes {{tt|mktime}} to attempt to determine if Daylight Saving Time was in effect. |
+ | |||
+ | If the conversion is successful, the {{tt|time}} object is modified. The all fields of {{tt|time}} are updated to fit their proper ranges. {{tt|time->tm_wday}} and {{tt|time->tm_yday}} are recalculated using information available in other fields. | ||
===Parameters=== | ===Parameters=== |
Revision as of 01:03, 23 April 2013
Defined in header <ctime>
|
||
std::time_t mktime( std::tm* time ); |
||
Converts local calendar time to a time since epoch as a time_t object. time->tm_wday
and time->tm_yday
are ignored.
A negative value of time->tm_isdst
causes mktime
to attempt to determine if Daylight Saving Time was in effect.
If the conversion is successful, the time
object is modified. The all fields of time
are updated to fit their proper ranges. time->tm_wday
and time->tm_yday
are recalculated using information available in other fields.
Contents |
Parameters
time | - | pointer to a std::tm object specifying local calendar time to convert |
Return value
Time since epoch as a std::time_t object on success or -1 if time
cannot be represented as a std::time_t object.
Example
Display the time 100 months ago
Run this code
#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'; }
Output:
Today is Wed Dec 28 09:56:10 2011 EST 100 months ago was Thu Aug 28 10:56:10 2003 EDT
See also
C documentation for mktime
|