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];
/* tm 構造体のサンプルの読み込み */
t.tm_sec = 1; /* 秒 */
t.tm_min = 30; /* 分 */
t.tm_hour = 9; /* 時 */
t.tm_mday = 22; /* 日 */
t.tm_mon = 11; /* 月 */
t.tm_year = 56; /* 年 - 下 2 桁のみ */
t.tm_wday = 4; /* 曜日 */
t.tm_yday = 0; /* asctime では表示されない */
t.tm_isdst = 0; /* 夏時間。asctime では表示されない */
/* 構造体をヌルで終わる文字列に変換します */
strcpy(str, asctime(&t));
printf("%s\n", str);
return 0;
}
移植性
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
asctime |
+ |
+ |
+ |
+ |
_wasctime |
+ |