localtime() – C语言库函数
C的库函数 struct tm *localtime(const time_t *timer) 使用所指出的时间由定时器填充atm值表示相应的本地时间的时间值的计时器的结构被划分成结构tm表示在本地时区。
声明
以下是对localtime() 函数声明。
struct tm *localtime(consttime_t*timer)
参数
-
timer -- 这是一个time_t值表示日历时间的指针。
返回值
这个函数返回指向tm结构,以下是tm结构的时间填充信息:
struct tm {int tm_sec;/* seconds, range 0 to 59 */int tm_min;/* minutes, range 0 to 59 */int tm_hour;/* hours, range 0 to 23 */int tm_mday;/* day of the month, range 1 to 31 */int tm_mon;/* month, range 0 to 11 */int tm_year;/* The number of years since 1900 */int tm_wday;/* day of the week, range 0 to 6 */int tm_yday;/* day in the year, range 0 to 365 */int tm_isdst;/* daylight saving time */};
例子
下面的例子演示了如何使用localtime() 函数。
#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);}
让我们编译和运行上面的程序,这将产生以下结果:
Current local time and date: Thu Aug 23 09:12:05 2012