1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified Sat Jul 24 19:49:27 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Fri Apr 26 12:38:55 MET DST 1996 by Martin Schulze (joey@linux.de)
29 .\" Modified 2001-11-13, aeb
30 .\" Modified 2004-11-16, mtk
32 .\" Japanese Version Copyright (c) 1997 Hiroaki Nagoya
33 .\" all rights reserved.
34 .\" Translated 1997-02-10, Hiroaki Nagoya <nagoya@is.titech.ac.jp>
35 .\" Updated 1999-09-01, Kentaro Shirakata <argrath@ub32.org>
36 .\" Updated 2001-10-15, Kentaro Shirakata <argrath@ub32.org>
37 .\" Updated 2001-12-13, Kentaro Shirakata <argrath@ub32.org>
38 .\" Updated 2002-01-03, Kentaro Shirakata <argrath@ub32.org>
39 .\" Updated 2005-02-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
40 .\" Updated 2008-04-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.79
41 .\" Updated 2008-08-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
42 .\" Updated 2008-11-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
44 .\"WORD: Coordinated Univarsal Time 協定世界時
45 .\"WORD: broken-down time 要素別の時刻
47 .TH CTIME 3 2010-02-25 "" "Linux Programmer's Manual"
49 asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r,
50 localtime_r \- 日付と時刻を要素別の時刻や ASCII に変換する
55 .BI "char *asctime(const struct tm *" tm );
57 .BI "char *asctime_r(const struct tm *" tm ", char *" buf );
59 .BI "char *ctime(const time_t *" timep );
61 .BI "char *ctime_r(const time_t *" timep ", char *" buf );
63 .BI "struct tm *gmtime(const time_t *" timep );
65 .BI "struct tm *gmtime_r(const time_t *" timep ", struct tm *" result );
67 .BI "struct tm *localtime(const time_t *" timep );
69 .BI "struct tm *localtime_r(const time_t *" timep ", struct tm *" result );
71 .BI "time_t mktime(struct tm *" tm );
76 .RB ( feature_test_macros (7)
86 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
87 _SVID_SOURCE || _POSIX_SOURCE
96 \fItime_t\fP 型のカレンダー時刻を引き数にとる。
97 引き数が絶対値として解釈される場合は、時刻紀元 (Epoch;
98 1970-01-01 00:00:00 +0000 (UTC)) からの経過秒数と解釈される。
105 年・月・日などに分離された要素別の時刻を引き数とする。
107 要素別の時刻は \fI<time.h>\fP で以下のように定義されている
115 int tm_hour; /* 時間 */
119 int tm_wday; /* 曜日 */
120 int tm_yday; /* 年内通算日 */
121 int tm_isdst; /* 夏時間 */
126 \fItm\fP 構造体のメンバーは以下の通り:
129 秒数、ふつうは 0 から 59 までの値、
130 しかし閏秒のため 60 までの値は許される。
136 真夜中からの通算時間、0 から 23 までの値。
139 月はじめからの日数、1 から 31 までの値。
142 1月からの通算月数、0 から 11 までの値。
148 日曜日からの通算日数(曜日)。0 から 6 までの値。
151 1 月 1 日からの通算日数、0 から 365 までの値。
155 正の値ならば夏時間は有効になり、0 ならば無効、負の値ならばこの情報には
160 .BI asctime(localtime( t ))
165 "Wed Jun 30 21:49:08 1993\\n"
168 という形式の NULL 終端された文字列へ変換する。
170 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" である。
171 月の略称は "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
172 "Sep", "Oct", "Nov", "Dec" である。
173 返り値は、静的 (static) に割り当てられた文字列へのポインタである。
174 この文字列は、日付・時刻関数のいずれかが呼び出されると上書きされることがある。
175 またこの関数は大域変数 \fItzname\fP, \fItimezone\fP, \fIdaylight\fP
182 文字列はユーザーが用意したバッファに格納される。バッファのサイズは
183 少なくとも 26 バイト以上でなければならない。
184 この関数は \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP
189 は、カレンダー時刻 \fItimep\fP を
190 協定世界時 (UTC) での要素別の時刻へ変換する。
191 年が整数型に収まらない場合、NULL を返す。
192 返り値は静的に確保された構造体を指しており、この後で
193 日付や時刻に関する関数のいずれかが呼び出されると
197 データはユーザーが用意した構造体に格納される。
201 は、カレンダー時刻 \fItimep\fP を
202 ユーザが指定したタイムゾーンでの時刻要素別の表現へ変換する。
206 大域変数 \fItzname\fP に現在のタイムゾーンの情報を設定する。
207 また、\fItimezone\fP に協定世界時 (UTC) とローカル標準時との
209 一年の一部で夏時間が適用される場合は \fIdaylight\fP に 0 が設定される。
210 返り値は静的に確保された構造体を指しており、この後で
211 日付や時刻に関する関数のいずれかが呼び出されると
215 データはユーザーが用意した構造体に格納される。
216 この関数は \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP
223 と同じ形式の NULL 終端された文字列へ変換する。
224 返り値は静的に割り当てられた文字列へのポインタである。この文字列は、
225 日付・時刻関数のいずれかが呼び出されると上書きされることがある。
229 文字列はユーザーが用意したバッファに格納される。バッファのサイズは
230 少なくとも 26 バイト以上でなければならない。
234 は、(ローカルタイムで記述されている) 要素別の時刻を
235 カレンダー時刻へ変換する。この際、呼び出し元がフィールド
245 構造体で渡された時刻で夏時間 (daylight saving time; DST) が有効になって
247 正の値は夏時間が有効であることを意味する。
250 は (タイムゾーン情報とシステムのデータベースを使って)
251 指定された時刻で夏時間が有効かどうかを判断する必要があることを意味する。
256 構造体の各フィールドを以下のように修正する。
260 には他のフィールドの内容から求めた値を設定する。
261 構造体の要素が有効な範囲にない場合、正規化される
262 (例えば、10 月 40 日は 11 月 9 日に変更される)。
264 には (最初の値にかかわらず) 正の値か 0 が設定される。
265 正の値は指定された時間で夏時間が有効であることを示し、
270 大域変数 \fItzname\fP が現在のタイムゾーンに設定される。
272 要素別の時刻をカレンダー時刻 (紀元 (Epoch) からの秒数) で表現できない場合、
276 を返し、要素別の時刻の構造体メンバーを変更しない。
278 各関数はそれぞれ前述した値を返す。エラーの場合は NULL
304 の 4 つの関数は静的データへのポインタを返すので、スレッドセーフではない。
320 型の配列かのどちらかの静的オブジェクトを返すものとする。
321 これらの関数のいずれかを実行すると、他の関数のどれかがこれらの
322 静的オブジェクトのどちらかに格納して返した情報が上書きされるかも
324 このことは glibc の実装で起こりうる。
328 に 0 を指定すると前月の最終日を意味していると解釈される。
335 \fIstruct tm\fP に以下のフィールドが追加される。
339 long tm_gmtoff; /* Seconds east of UTC */
340 const char *tm_zone; /* Timezone abbreviation */
344 これは BSD 拡張であり、4.3BSD-Reno から現れた。
350 が呼ばれたかのように振舞うことが要求されているが、
353 .\" http://thread.gmane.org/gmane.comp.time.tz/2034/ を参照。
361 .BR gettimeofday (2),