標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
ISO C |
両方 |
#include <time.h>
struct tm *localtime(const time_t *timeval);
#define _LARGE_TIME_API
#include <time.h>
struct tm *localtime64(const time64_t *timeval);
localtime() 関数は、timeval で指定されるカレンダー時間を、現地時間で表され るブロークンダウン時間へ変換します。カレンダー時間は、通常、time() 関数を呼び出して得られます。
localtime64() 関数は、localtime() とまったく同じように動作します。ただし、2038 年 1 月 19 日の 03:14:07 UTC を超え、9999 年 12 月 31 日の 23:59:59 UTC を限度とするカレンダー時間を指す time64_t 値をブレークダウンする点を除きます。
timeval で指定されるカレンダー時間に相当する、現地時間で表されるブロークンダウン時間を含む、tm 構造体へのポイ ンターを戻します。カレンダー時間を変換できない場合、localtime() は NULL ポインター を戻します。tm 構造体のフィールドの説明については、time.h を参照してください。
⁄* CELEBL07
This example queries the system clock and displays the local time.
*⁄
#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm *newtime;
time_t ltime;
time(<ime);
newtime = localtime(<ime);
printf("The date and time is %s", asctime(newtime));
}
出力
The date and time is Fri Jun 16 15:00:00 2006