標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
ISO C |
両方 |
#include <time.h>
char *asctime(const struct tm *timeptr);
#define _LARGE_TIME_API
#include <time.h>
char asctime64(const struct tm *timeptr);
timeptr で示される構造体として保管された 時間を文字ストリングに変換します。timeptr 値は、gmtime() または localtime() を 呼び出すと取得できます。両方の関数は、time.h で 定義した tm 構造体を指すポインターを戻します。
"%.3s %.3s%3d %.2d:%.2d:%.2d %d¥n"
以下に示すのは、戻されたストリングの例です。 Fri Jun 16 02:03:55 2006¥n¥0
関数 asctime64() は、asctime() とまったく同じように動作しますが、2038 年 1 月 19 日の 03:14:07 UTC を超え 9999 年 12 月 31 日の 23:59:59 UTC までを限度とするカレンダー時間を指す、time64_t 値を変換できます。
正常に実行された場合、asctime() は結果として生じた文字ストリングを 指すポインターを戻します。
正常に実行されなかった場合、NULL を戻します。
⁄* CELEBA06
This example polls the system clock and prints a message
giving the current time.
*⁄
#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm *newtime;
time_t ltime;
⁄* Get the time in seconds *⁄
time(<ime);
⁄* Break it down & store it in the structure tm *⁄
newtime = localtime(<ime);
⁄* Print the local time as a string *⁄
printf("The current date and time are %s",
asctime(newtime));
}
The current date and time are Fri Jun 16 13:29:51 2006