asctime

tm 構造体の要素別の時刻を文字列に変換します.

#include <time.h>
char *asctime(
    const struct tm *timeptr
);

asctime 関数は timeptr が指す構造体の要素別の時刻を次の形式の文字列に変換します.

形式

曜日(英語表記の先頭3文字) 月(英語表記の先頭3文字) 日 時:分:秒 年\n\0

変換例

Sun Sep 31 23:59:59 2008 \n\0

戻り値

  • 変換後の文字列へのポインタ

C言語サンプルプログラム

asctime 関数を使用して現在の時刻を文字列に変換するサンプルプログラムを以下に示します.

/* header files */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/* main */
int main(void) {
    time_t timer;
    struct tm *local;
    char *p;

    /* 現在時刻を取得 */
    timer = time(NULL);

    /* 地方時に変換 */
    local = localtime(&timer);

    /* 文字列への変換 */
    p = asctime(local);
    printf("%s\n", p);

    return EXIT_SUCCESS;
}

実行例

サンプルプログラムの実行結果は以下のようになります.

Tue Mar 31 23:07:58 2009