C++ <ctime> - tm structure type
The C++ <ctime> tm type is a structure holding a calendar date and time broken down into its components. The structure contains nine members of type int (in any order) as given below:
Member object | Type | Description |
---|---|---|
tm_sec | int | seconds after the minute - [0, 61] (until C++11) and [0, 60] (since C++11) |
tm_min | int | minutes after the hour – [0, 59] |
tm_hour | int | hours since midnight – [0, 23] |
tm_mday | int | day of the month – [1, 31] |
tm_mon | int | months since January – [0, 11] |
tm_year | int | years since 1900 |
tm_wday | int | days since Sunday – [0, 6] |
tm_yday | int | days since January 1 – [0, 365] |
tm_isdst | int | Daylight Saving Time flag. The value is positive if DST is in effect, zero if not and negative if no information is available. |
Example:
The example below shows the usage of tm type.
#include <iostream> #include <ctime> using namespace std; int main (){ struct tm start {}; start.tm_mday = 10; mktime(&start); //displaying the time cout<<asctime(&start); return 0; }
The output of the above code will be:
Wed Jan 10 00:00:00 1900
❮ C++ <ctime> Library