localtime_r() — 時間の変換 (再始動可能)

フォーマット

#include <time.h>
struct tm *localtime_r(const time_t *timeval, struct tm *result);

言語レベル

XPG4

スレッド・セーフ

はい

ロケール依存

この関数の振る舞いは、現行ロケールの LC_TOD カテゴリーの影響を受ける可能性があります。

説明

この関数は、localtime() の再始動可能バージョンです。 戻される構造体 result が保管される場所を渡す点を除き、localtime() と同じです。

戻り値

localtime_r() は、構造体 result へのポインターを戻します。 エラーの戻り値はありません。

この例では、システム・クロックを照会して、現地時間を表示します。
#include <time.h>
#include <stdio.h>
 
int main(void)
{
   struct tm newtime;
   time_t ltime;
   char buf[50];
 
   ltime=time(&ltime);
   localtime_r(&ltime, &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
*/