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