other versions
| CTIME(3) | Linux Programmer's Manual | CTIME(3) | 
名前¶
asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r, localtime_r - 日付と時刻を要素別の時刻や ASCII に変換する書式¶
#include <time.h>char *asctime(const struct tm *tm);char *asctime_r(const struct tm *tm, char *buf);char *ctime(const time_t *timep);char *ctime_r(const time_t *timep, char *buf);struct tm *gmtime(const time_t *timep);struct tm *gmtime_r(const time_t *timep, struct tm *result);struct tm *localtime(const time_t *timep);struct tm *localtime_r(const time_t *timep, struct tm *result);time_t mktime(struct tm *tm);
glibc 向けの機能検査マクロの要件 ( feature_test_macros(7) 参照):
_POSIX_C_SOURCE >= 1 ||
  _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE
説明¶
関数 ctime(), gmtime(), localtime() は time_t 型のカレンダー時刻を引き数にとる。 引き数が絶対値として解釈される場合は、時刻紀元 (Epoch; 1970-01-01 00:00:00 +0000 (UTC)) からの経過秒数と解釈される。 関数 asctime() と mktime() は 年・月・日などに分離された要素別の時刻を引き数とする。 要素別の時刻は <time.h> で以下のように定義されている tm 構造体に保持される。struct tm {
    int tm_sec;         /* 秒 */
    int tm_min;         /* 分 */
    int tm_hour;        /* 時間 */
    int tm_mday;        /* 日 */
    int tm_mon;         /* 月 */
    int tm_year;        /* 年 */
    int tm_wday;        /* 曜日 */
    int tm_yday;        /* 年内通算日 */
    int tm_isdst;       /* 夏時間 */
};
tm 構造体のメンバーは以下の通り:
- tm_sec
 - 秒数、ふつうは 0 から 59 までの値、 しかし閏秒のため 60 までの値は許される。
 
- tm_min
 - 分数、0 から 59 までの値。
 
- tm_hour
 - 真夜中からの通算時間、0 から 23 までの値。
 
- tm_mday
 - 月はじめからの日数、1 から 31 までの値。
 
- tm_mon
 - 1月からの通算月数、0 から 11 までの値。
 
- tm_year
 - 1900 年からの通算年数。
 
- tm_wday
 - 日曜日からの通算日数(曜日)。0 から 6 までの値。
 
- tm_yday
 - 1 月 1 日からの通算日数、0 から 365 までの値。
 
- tm_isdst
 - 夏時間が有効かどうかのフラグ。 正の値ならば夏時間は有効になり、0 ならば無効、負の値ならばこの情報には 意味がない。
 
"Wed Jun 30 21:49:08 1993\n"
返り値¶
各関数はそれぞれ前述した値を返す。エラーの場合は NULL ( mktime() では -1) を返す。準拠¶
POSIX.1-2001. C89 と C99 では asctime(), ctime(), gmtime(), localtime(), mktime() が規定されている。 POSIX.1-2008 は、 asctime(), asctime_r(), ctime(), ctime_r() を廃止予定としている。 代わりに、 strftime(3) の使用が推奨されている。注意¶
asctime(), ctime(), gmtime(), localtime() の 4 つの関数は静的データへのポインタを返すので、スレッドセーフではない。 これらの関数のスレッドセーフ版である asctime_r(), ctime_r(), gmtime_r(), localtime_r() は SUSv2 で規定されており、 libc 5.2.5 以降で利用できる。long tm_gmtoff; /* Seconds east of UTC */ const char *tm_zone; /* Timezone abbreviation */
関連項目¶
date(1), gettimeofday(2), time(2), utime(2), clock(3), difftime(3), strftime(3), strptime(3), timegm(3), tzset(3), time(7)この文書について¶
この man ページは Linux man-pages プロジェクトのリリース 3.41 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man-pages/ に書かれている。| 2010-02-25 |