struct tm
is a structure defined in the time.h
header file in C language. Each of the member objects of struct tm
contains the time and date stored on a machine.
Below is a table that outlines what each member of the struct
holds. The Daylight Saving Time flag is positive if it is daylight saving time, negative if it is unknown, and 0 if it is not daylight saving time. All the members are of type int
.
Member | |
tm_sec | seconds passed since last minute |
tm_min | minutes passed since hour |
tm_hour | hours passed since midnight |
tm_mday | day of the month |
tm_mon | months passed since January |
tm_year | year passed since 1900 |
tm_wday | days since Sunday |
tm_yday | days since first day of the year |
tm_isdst | Daylight Saving Time Flag |
The code below illustrates how you can use struct tm
to print the calendar time and date. The values for the members of the struct are set to Mon Feb 1 01:01:01 1901 using the (.)
operator.
#include<stdio.h>#include<time.h>int main() {struct tm value;value.tm_sec=1;value.tm_min=1;value.tm_hour=1;value.tm_mday=1;value.tm_mon=1;value.tm_year=1;value.tm_hour=1;value.tm_wday=1;value.tm_yday=1;printf("Time and date: %s", asctime(&value));return 0;}
Free Resources