C++ Standard Library C++ STL Library

C++ <cwchar> - tm structure type



The C++ <cwchar> 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 objectTypeDescription
tm_secintseconds after the minute - [0, 61] (until C++11) and [0, 60] (since C++11)
tm_minintminutes after the hour – [0, 59]
tm_hourinthours since midnight – [0, 23]
tm_mdayintday of the month – [1, 31]
tm_monintmonths since January – [0, 11]
tm_yearintyears since 1900
tm_wdayintdays since Sunday – [0, 6]
tm_ydayintdays since January 1 – [0, 365]
tm_isdstintDaylight 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 <cwchar>
#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++ <cwchar> Library