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
*/