C Standard Library

C <time.h> - tm structure type



The C <time.h> 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 C99) and [0, 60] (since C99)
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 <stdio.h>
#include <time.h>
 
int main (){
  struct tm start = {.tm_mday = 10};

  mktime(&start);

  //displaying the time
  printf("%s", asctime(&start));

  return 0;
}

The output of the above code will be:

Wed Jan 10 00:00:00 1900

❮ C <time.h> Library