OSDN Git Service

(split) LDP: draft snapshot generated from latest ja.po files.
[linuxjm/LDP_man-pages.git] / draft / man3 / ctime.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
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.
6 .\"
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.
11 .\"
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
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\"     386BSD man pages
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 2001-12-13, joey, aeb
31 .\" Modified 2004-11-16, mtk
32 .\"
33 .\"*******************************************************************
34 .\"
35 .\" This file was generated with po4a. Translate the source file.
36 .\"
37 .\"*******************************************************************
38 .TH CTIME 3 2010\-02\-25 "" "Linux Programmer's Manual"
39 .SH 名前
40 asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r,
41 localtime_r \- 日付と時刻を要素別の時刻や ASCII に変換する
42 .SH 書式
43 .nf
44 \fB#include <time.h>\fP
45 .sp
46 \fBchar *asctime(const struct tm *\fP\fItm\fP\fB);\fP
47 .br
48 \fBchar *asctime_r(const struct tm *\fP\fItm\fP\fB, char *\fP\fIbuf\fP\fB);\fP
49 .sp
50 \fBchar *ctime(const time_t *\fP\fItimep\fP\fB);\fP
51 .br
52 \fBchar *ctime_r(const time_t *\fP\fItimep\fP\fB, char *\fP\fIbuf\fP\fB);\fP
53 .sp
54 \fBstruct tm *gmtime(const time_t *\fP\fItimep\fP\fB);\fP
55 .br
56 \fBstruct tm *gmtime_r(const time_t *\fP\fItimep\fP\fB, struct tm *\fP\fIresult\fP\fB);\fP
57 .sp
58 \fBstruct tm *localtime(const time_t *\fP\fItimep\fP\fB);\fP
59 .br
60 \fBstruct tm *localtime_r(const time_t *\fP\fItimep\fP\fB, struct tm *\fP\fIresult\fP\fB);\fP
61 .sp
62 \fBtime_t mktime(struct tm *\fP\fItm\fP\fB);\fP
63 .fi
64 .sp
65 .in -4n
66 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
67 .in
68 .ad l
69 .sp
70 \fBasctime_r\fP(), \fBctime_r\fP(), \fBgmtime_r\fP(), \fBlocaltime_r\fP():
71 .RS
72 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE
73 || _POSIX_SOURCE
74 .RE
75 .ad
76 .SH 説明
77 関数 \fBctime\fP(), \fBgmtime\fP(), \fBlocaltime\fP()  は \fItime_t\fP 型のカレンダー時刻を引き数にとる。
78 引き数が絶対値として解釈される場合は、時刻紀元 (Epoch; 1970\-01\-01 00:00:00 +0000 (UTC))
79 からの経過秒数と解釈される。
80 .PP
81 関数 \fBasctime\fP()  と \fBmktime\fP()  は 年・月・日などに分離された要素別の時刻を引き数とする。
82 .PP
83 要素別の時刻は \fI<time.h>\fP で以下のように定義されている \fItm\fP 構造体に保持される。
84 .sp
85 .in +4n
86 .nf
87 struct tm {
88     int tm_sec;         /* 秒 */
89     int tm_min;         /* 分 */
90     int tm_hour;        /* 時間 */
91     int tm_mday;        /* 日 */
92     int tm_mon;         /* 月 */
93     int tm_year;        /* 年 */
94     int tm_wday;        /* 曜日 */
95     int tm_yday;        /* 年内通算日 */
96     int tm_isdst;       /* 夏時間 */
97 };
98 .fi
99 .in
100 .PP
101 \fItm\fP 構造体のメンバーは以下の通り:
102 .TP  10
103 \fItm_sec\fP
104 秒数、ふつうは 0 から 59 までの値、 しかし閏秒のため 60 までの値は許される。
105 .TP 
106 \fItm_min\fP
107 分数、0 から 59 までの値。
108 .TP 
109 \fItm_hour\fP
110 真夜中からの通算時間、0 から 23 までの値。
111 .TP 
112 \fItm_mday\fP
113 月はじめからの日数、1 から 31 までの値。
114 .TP 
115 \fItm_mon\fP
116 1月からの通算月数、0 から 11 までの値。
117 .TP 
118 \fItm_year\fP
119 1900 年からの通算年数。
120 .TP 
121 \fItm_wday\fP
122 日曜日からの通算日数(曜日)。0 から 6 までの値。
123 .TP 
124 \fItm_yday\fP
125 1 月 1 日からの通算日数、0 から 365 までの値。
126 .TP 
127 \fItm_isdst\fP
128 夏時間が有効かどうかのフラグ。 正の値ならば夏時間は有効になり、0 ならば無効、負の値ならばこの情報には 意味がない。
129 .PP
130 \fBctime(\fP\fIt\fP\fB)\fP 関数は、 \fBasctime(localtime(\fP\fIt\fP\fB))\fP と等価である。 カレンダー時刻 \fIt\fP を
131 .sp
132 .RS
133 "Wed Jun 30 21:49:08 1993\en"
134 .RE
135 .sp
136 という形式の NULL 終端された文字列へ変換する。 曜日の略称は "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
137 "Sat" である。 月の略称は "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
138 "Sep", "Oct", "Nov", "Dec" である。 返り値は、静的 (static) に割り当てられた文字列へのポインタである。
139 この文字列は、日付・時刻関数のいずれかが呼び出されると上書きされることがある。 またこの関数は大域変数 \fItzname\fP, \fItimezone\fP,
140 \fIdaylight\fP に現在のタイムゾーンの情報を設定する (\fBtzset\fP(3)  参照)。 リエントラント版である \fBctime_r\fP()
141 も同様だが、 文字列はユーザーが用意したバッファに格納される。バッファのサイズは 少なくとも 26 バイト以上でなければならない。 この関数は
142 \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP を設定する必要はない。
143 .PP
144 関数 \fBgmtime\fP()  は、カレンダー時刻 \fItimep\fP を 協定世界時 (UTC) での要素別の時刻へ変換する。
145 年が整数型に収まらない場合、NULL を返す。 返り値は静的に確保された構造体を指しており、この後で 日付や時刻に関する関数のいずれかが呼び出されると
146 上書きされる可能性がある。 \fBgmtime_r\fP()  も同様だが、 データはユーザーが用意した構造体に格納される。
147 .PP
148 関数 \fBlocaltime\fP()  は、カレンダー時刻 \fItimep\fP を ユーザが指定したタイムゾーンでの時刻要素別の表現へ変換する。 この関数は
149 \fBtzset\fP(3)  を呼び出したかのように振舞い、 大域変数 \fItzname\fP に現在のタイムゾーンの情報を設定する。
150 また、\fItimezone\fP に協定世界時 (UTC) とローカル標準時との 時差の秒数を設定し、 一年の一部で夏時間が適用される場合は
151 \fIdaylight\fP に 0 が設定される。 返り値は静的に確保された構造体を指しており、この後で 日付や時刻に関する関数のいずれかが呼び出されると
152 上書きされる可能性がある。 \fBlocaltime_r\fP()  も同様だが、 データはユーザーが用意した構造体に格納される。 この関数は
153 \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP を設定する必要はない。
154 .PP
155 関数 \fBasctime\fP()  は、要素別の時刻 \fItm\fP を \fBctime\fP()  と同じ形式の NULL 終端された文字列へ変換する。
156 返り値は静的に割り当てられた文字列へのポインタである。この文字列は、 日付・時刻関数のいずれかが呼び出されると上書きされることがある。
157 リエントラント版である \fBasctime_r\fP()  も同様だが、 文字列はユーザーが用意したバッファに格納される。バッファのサイズは 少なくとも
158 26 バイト以上でなければならない。
159 .PP
160 関数 \fBmktime\fP()  は、(ローカルタイムで記述されている) 要素別の時刻を カレンダー時刻へ変換する。この際、呼び出し元がフィールド
161 \fItm_wday\fP と \fItm_yday\fP で指定した値は無視される。 \fBmktime\fP()  は、フィールド \fItm_isdst\fP
162 で指定された値により、 \fItm\fP 構造体で渡された時刻で夏時間 (daylight saving time; DST) が有効になって いるかを知る。
163 正の値は夏時間が有効であることを意味する。 負の値であれば、 \fBmktime\fP()  は (タイムゾーン情報とシステムのデータベースを使って)
164 指定された時刻で夏時間が有効かどうかを判断する必要があることを意味する。
165
166 \fBmktime\fP()  は \fItm\fP 構造体の各フィールドを以下のように修正する。 \fItm_wday\fP と \fItm_yday\fP
167 には他のフィールドの内容から求めた値を設定する。 構造体の要素が有効な範囲にない場合、正規化される (例えば、10 月 40 日は 11 月 9
168 日に変更される)。 \fItm_isdst\fP には (最初の値にかかわらず) 正の値か 0 が設定される。
169 正の値は指定された時間で夏時間が有効であることを示し、 0 は無効であることを示す。 関数 \fBmktime\fP()  を呼び出すと、 大域変数
170 \fItzname\fP が現在のタイムゾーンに設定される。
171
172 要素別の時刻をカレンダー時刻 (紀元 (Epoch) からの秒数) で表現できない場合、 \fBmktime\fP()  は \fI(time_t)\ (\-1)\fP を返し、要素別の時刻の構造体メンバーを変更しない。
173 .SH 返り値
174 各関数はそれぞれ前述した値を返す。エラーの場合は NULL (\fBmktime\fP()  では \-1) を返す。
175 .SH 準拠
176 POSIX.1\-2001.  C89 と C99 では \fBasctime\fP(), \fBctime\fP(), \fBgmtime\fP(),
177 \fBlocaltime\fP(), \fBmktime\fP()  が規定されている。 POSIX.1\-2008 は、 \fBasctime\fP(),
178 \fBasctime_r\fP(), \fBctime\fP(), \fBctime_r\fP()  を廃止予定としている。 代わりに、 \fBstrftime\fP(3)
179 の使用が推奨されている。
180 .SH 注意
181 \fBasctime\fP(), \fBctime\fP(), \fBgmtime\fP(), \fBlocaltime\fP()  の 4
182 つの関数は静的データへのポインタを返すので、スレッドセーフではない。 これらの関数のスレッドセーフ版である \fBasctime_r\fP(),
183 \fBctime_r\fP(), \fBgmtime_r\fP(), \fBlocaltime_r\fP()  は SUSv2 で規定されており、 libc 5.2.5
184 以降で利用できる。
185
186 POSIX.1\-2001 では、「関数 \fBasctime\fP(), \fBctime\fP(), \fBgmtime\fP(), \fBlocaltime\fP()
187 は、要素別の時刻の構造体か \fIchar\fP 型の配列かのどちらかの静的オブジェクトを返すものとする。
188 これらの関数のいずれかを実行すると、他の関数のどれかがこれらの 静的オブジェクトのどちらかに格納して返した情報が上書きされるかも
189 しれない。」となっている。 このことは glibc の実装で起こりうる。
190 .LP
191 glibc を含む多くの実装では、 \fItm_mday\fP に 0 を指定すると前月の最終日を意味していると解釈される。
192 .LP
193 glibc では、 \fI<time.h>\fP がインクルードされる前に \fB_BSD_SOURCE\fP が定義されると、 \fIstruct
194 tm\fP に以下のフィールドが追加される。
195 .sp
196 .RS
197 .nf
198 long tm_gmtoff;           /* Seconds east of UTC */
199 const char *tm_zone;      /* Timezone abbreviation */
200 .fi
201 .RE
202 .sp
203 これは BSD 拡張であり、4.3BSD\-Reno から現れた。
204
205 .\" See http://thread.gmane.org/gmane.comp.time.tz/2034/
206 POSIX.1\-2004 によると、 \fBlocaltime\fP()  はあたかも \fBtzset\fP(3)
207 が呼ばれたかのように振舞うことが要求されているが、 \fBlocaltime_r\fP()  にはこの要件はない。 移植性が必要なコードでは、
208 \fBlocaltime_r\fP()  の前に \fBtzset\fP(3)  を呼び出しておくべきである。
209 .SH 関連項目
210 \fBdate\fP(1), \fBgettimeofday\fP(2), \fBtime\fP(2), \fButime\fP(2), \fBclock\fP(3),
211 \fBdifftime\fP(3), \fBstrftime\fP(3), \fBstrptime\fP(3), \fBtimegm\fP(3), \fBtzset\fP(3),
212 \fBtime\fP(7)