C library functions - localtime ()
description
C library functionsstruct tm * localtime (const time_t * timer) uses the value to fill timer tmstructure.timer value is decomposed into tmstructure, and represents the local time zone.
statement
The following is a statement localtime () function.
struct tm *localtime(const time_t *timer)
parameter
- timer - This is a pointer to a pointer showing a time_t calendar time value.
return value
This function returns a pointer totm structure, the structure is filled with time information.Below are details of the tm structure:
struct tm { int tm_sec; /* 秒,范围从 0 到 59 */ int tm_min; /* 分,范围从 0 到 59 */ int tm_hour; /* 小时,范围从 0 到 23 */ int tm_mday; /* 一月中的第几天,范围从 1 到 31 */ int tm_mon; /* 月份,范围从 0 到 11 */ int tm_year; /* 自 1900 起的年数 */ int tm_wday; /* 一周中的第几天,范围从 0 到 6 */ int tm_yday; /* 一年中的第几天,范围从 0 到 365 */ int tm_isdst; /* 夏令时 */ };
Examples
The following example demonstrates the localtime () function is used.
#include <stdio.h> #include <time.h> int main () { time_t rawtime; struct tm *info; char buffer[80]; time( &rawtime ); info = localtime( &rawtime ); printf("当前的本地时间和日期:%s", asctime(info)); return(0); }
Let's compile and run the above program, which will result in the following:
当前的本地时间和日期:Thu Aug 23 09:12:05 2012