Definition | #include <time.h> struct tm *localtime(const time_t *sec_p);
The latest date which can be displayed with | |
Return val. | Pointer to the calculated structure. | |
struct tm
{
int tm_sec; /* seconds (0-59) */
int tm_min; /* minutes (0-59) */
int tm_hour; /* hours (0-23) */
int tm_mday; /* day of the month (1-31) */
int tm_mon; /* month from the start of the year (0-11) */
int tm_year; /* years since 1900 */
int tm_wday; /* weekday (0-6, Sunday=0) */
int tm_yday; /* days since January 1 (0-365) */
int tm_isdst; /* daylight saving time flag */
};
| ||
NULL | In the event of an error | |
Notes |
| |
Example | #include <time.h>
#include <stdio.h>
struct tm *t;
time_t clk;
char *s;
int main(void)
{
clk = time((time_t *)0);
t = localtime(&clk);
printf("Year: %d\n", t->tm_year + 1900);
printf("Time in hours: %d\n", t->tm_hour);
printf("Day of the year: %d\n", t->tm_yday);
s = asctime(t);
printf("%s", s);
return 0;
}
| |