asctime
Time.h:インデックス への移動
ヘッダー ファイル
time.h
カテゴリ
日付/時刻ルーチン
プロトタイプ
char *asctime(const struct tm *tblock);
wchar_t *_wasctime(const struct tm *tblock);
説明
asctime は日付と時刻を ASCII に変換します。
wasctime は日付と時刻を wchar_t 文字列に変換します。
asctime と wasctime は、構造体に格納された時刻を、次の形式の 26 文字の(ワイド)文字列に変換します。
Mon Nov 21 11:31:54 1983\n\0
すべてのフィールドは固定幅です。 出力文字列の曜日および月は次のように対応します。
tm パラメータ/有効な値の範囲/出力
tm.mon(月)/0-11/0=Jan、1=Feb など
tm.day(曜日)/0-6/0=Sun、1=Mon など
戻り値
asctime および _wasctime は、日時を保有する(ワイド)文字の文字列へのポインタを返します。この文字列は静的で、各呼び出しで上書きされます。asctime は、*tblock に構造体として格納されている時間を、ctime 文字列と同じ形式の 26 文字の文字列に変換します:
Sun Sep 16 01:03:52 1973\n\0
例
#include <string.h>
#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm t;
char str[80];
/* sample loading of tm structure */
t.tm_sec = 1; /* Seconds */
t.tm_min = 30; /* Minutes */
t.tm_hour = 9; /* Hour */
t.tm_mday = 22; /* Day of the Month */
t.tm_mon = 11; /* Month */
t.tm_year = 56; /* Year - does not include century */
t.tm_wday = 4; /* Day of the week */
t.tm_yday = 0; /* Does not show in asctime */
t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */
/* converts structure to null terminated string */
strcpy(str, asctime(&t));
printf("%s\n", str);
return 0;
}
移植性
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
asctime |
+ |
+ |
+ |
+ |
_wasctime |
+ |