C examples for time.h:struct tm
type
<ctime> <time.h> <cwchar>
Time structure
Structure containing a calendar date and time broken down into its components.
The structure contains nine members of type int, which are:
Member | Type | Meaning | Range |
---|---|---|---|
tm_sec | int | seconds after the minute | 0-60 |
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 | N/A |
The Daylight Saving Time flag tm_isdst may have the following value
Parameter | Description |
---|---|
>0 | if Daylight Saving Time is in effect, |
0 | if Daylight Saving Time is not in effect, |
<0 | if the information is not available. |
tm_sec is generally 0-59. The extra range is to accommodate for leap seconds in certain systems.
#include <stdio.h> #include <time.h> int main ()//from www . j av a 2s. c om { time_t timer; struct tm year2020 = {0}; double seconds; year2020.tm_hour = 0; year2020.tm_min = 0; year2020.tm_sec = 0; year2020.tm_year = 120; year2020.tm_mon = 0; year2020.tm_mday = 1; time(&timer); /* get current time; same as: timer = time(NULL) */ seconds = difftime(timer,mktime(&year2020)); printf ("%.f seconds since January 1, 2000 in the current timezone", seconds); return 0; }