C library functions -localtime()

C Standard Library - <time.h>

Description

C Library Functionsstruct tm *localtime(const time_t *timer)Use the value of timer to filltmStructure.timerthe value is decomposed intotmthe structure, and represent it in the local time zone.

Declaration

Below is the declaration of the localtime() function.

struct tm *localtime(const time_t *timer)

Parameter

  • timer-- This is a pointer to a time_t value representing calendar time.

Return Value

this function returns a pointer totmA pointer to a structure that carries the filled time information. Below are the details of the tm structure:

struct tm { int tm_sec; /*Seconds, range from 0 to 59*/ int tm_min; /*Minutes, range from 0 to 59*/ int tm_hour; /*Hours, range from 0 to 23*/ int tm_mday; /*Day of the month, range from 1 to 31*/ int tm_mon; /*Month, range from 0 to 11*/ int tm_year; /*Years since 1900*/ int tm_wday; /*Day of the week, range from 0 to 6*/ int tm_yday; /*Day of the year, range from 0 to 365*/ int tm_isdst; /*Daylight saving time*/ };

Example

The following example demonstrates the usage of the localtime() function.

Example

#include <stdio.h> #include <time.h> int main () { time_t rawtime; struct tm *info; char buffer[80]; time( &rawtime ); info = localtime( &rawtime ); printf("Current local time and date: %s", asctime(info)); return(0); }

Let us compile and run the above program, which will produce the following results:

当前的本地时间和日期:Thu Aug 23 09:12:05 2012

C Standard Library - <time.h>

other extensions