localtime_r ()- 转换时间 (可重新启动)
格式
#include <time.h>
struct tm *localtime_r(const time_t *timeval, struct tm *result);语言级别
XPG4
线程安全
是
语言环境敏感
此函数的行为可能受当前语言环境的 LC_TOD 类别影响。
描述
此函数是 localtime()的可重新启动版本。 它与 localtime() 相同,只是它传递到存储返回的结构 result的位置。
返回值
localtime_r() 返回指向结构结果的指针。 没有错误返回值。
示例
此示例查询系统时钟并显示本地时间。
#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm newtime;
time_t ltime;
char buf[50];
ltime=time(<ime);
localtime_r(<ime, &newtime);
printf("The date and time is %s", asctime_r(&newtime, buf));
}
/************** If the local time is 3 p.m. February 15, 2008, **********
************************* the output should be: *********************
The date and time is Fri Feb 15 15:00:00 2008
*/