OSDN Git Service

(split) LDP: Update releases based on LDP 3.52 release
[linuxjm/LDP_man-pages.git] / release / man3 / strftime.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\"     GNU texinfo documentation on glibc date/time functions.
30 .\" Modified Sat Jul 24 18:03:44 1993 by Rik Faith (faith@cs.unc.edu)
31 .\" Applied fix by Wolfgang Franke, aeb, 961011
32 .\" Corrected return value, aeb, 970307
33 .\" Added Single UNIX Spec conversions and %z, aeb/esr, 990329.
34 .\" 2005-11-22 mtk, added Glibc Notes covering optional 'flag' and
35 .\"           'width' components of conversion specifications.
36 .\"
37 .\"*******************************************************************
38 .\"
39 .\" This file was generated with po4a. Translate the source file.
40 .\"
41 .\"*******************************************************************
42 .TH STRFTIME 3 2013\-06\-28 GNU "Linux Programmer's Manual"
43 .SH 名前
44 strftime \- 日付および時刻の文字列への変換
45 .SH 書式
46 .nf
47 \fB#include <time.h>\fP
48 .sp
49 \fBsize_t strftime(char *\fP\fIs\fP\fB, size_t \fP\fImax\fP\fB, const char *\fP\fIformat\fP\fB,\fP
50 \fB                const struct tm *\fP\fItm\fP\fB);\fP
51 .fi
52 .SH 説明
53 .\" FIXME POSIX says: Local timezone information is used as though
54 .\" strftime() called tzset().  But this doesn't appear to be the case
55 \fBstrftime\fP()  関数 は、要素別の時刻 \fItm\fP の内容を \fIformat\fP で指定された書式指定にしたがって変換し、 長さ
56 \fImax\fP の文字列 \fIs\fP に書き込む。
57 .PP
58 書式指定は NULL 終端された文字列であり、 「変換指定 (conversion specification)」と呼ばれる特別な文字列を
59 含まることができる。 各々の変換指定は \(aq%\(aq 文字で始まり、 「変換指定文字 (conversion specifier
60 character)」と呼ばれる 何らか他の文字で終端される。上記以外の全ての文字列は 「通常の文字列 (ordinary character
61 sequence)」となる。
62 .PP
63 (NULL バイトも含む) 通常の文字列内の文字は、 そのまま \fIformat\fP から \fIs\fP にコピーされる。
64 一方、変換指定の文字は以下のように置換される。
65 .TP 
66 \fB%a\fP
67 現在のロケールにおける曜日の省略名。
68 .TP 
69 \fB%A\fP
70 現在のロケールにおける曜日の完全な名前。
71 .TP 
72 \fB%b\fP
73 現在のロケールにおける月の省略名。
74 .TP 
75 \fB%B\fP
76 現在のロケールにおける月の完全な名前。
77 .TP 
78 \fB%c\fP
79 現在のロケールにおいて一般的な日付・時刻の表記。
80 .TP 
81 \fB%C\fP
82 世紀 (西暦年の上 2 桁)。 (SU)
83 .TP 
84 \fB%d\fP
85 月内通算日 (10 進数表記) (01\-31)。
86 .TP 
87 \fB%D\fP
88 \fB%m/%d/%y\fP と等価。(うえっ、アメリカ専用だ。アメリカ以外の国では \fB%d/%m/%y\fP
89 の方が一般的だ。紛らわしいので、使用すべきではない。) (SU)
90 .TP 
91 \fB%e\fP
92 \fB%d\fP と同様に月内通算日を 10 進数で表現するが、 1 桁の場合 10 の位にゼロを置かずスペースを置く。(SU)
93 .TP 
94 \fB%E\fP
95 別形式を使用する際の修飾子。下記参照。 (SU)
96 .TP 
97 \fB%F\fP
98 \fB%Y\-%m\-%d\fP と等価 (ISO\ 8601 形式の日付フォーマット)。 (C99)
99 .TP 
100 \fB%G\fP
101 ISO\ 8601 週単位表記の年 (week\-based year; 「注意」の節を参照)。 世紀も 10 進数で表す。 ISO 週番号 (\fB%V\fP
102 を参照) に対応した 4 桁の西暦年。 これは基本的には \fB%Y\fP と同じ形式だが、ISO 週数が前年や翌年になる
103 場合にはその年が使用される点が異なる。(TZ)
104 .TP 
105 \fB%g\fP
106 \fB%G\fP と同様。但し、世紀を含まず下 2 桁のみを表示 (00\-99)。 (TZ)
107 .TP 
108 \fB%h\fP
109 \fB%b\fP と等価 (SU)
110 .TP 
111 \fB%H\fP
112 24 時間表記での時 (hour)。 (00\-23)
113 .TP 
114 \fB%I\fP
115 12 時間表記での時 (hour)。 (01\-12)
116 .TP 
117 \fB%j\fP
118 年の初めから通算の日数。 (001\-366)
119 .TP 
120 \fB%k\fP
121 24 時間表記での時 (0\-23)。 1 桁の場合には前にゼロでなくスペースが置かれる。 (\fB%H\fP も参照) (TZ)
122 .TP 
123 \fB%l\fP
124 12 時間表記での時 (0\-12)。 1 桁の場合には前にゼロでなくスペースが置かれる。 (\fB%I\fP も参照) (TZ)
125 .TP 
126 \fB%m\fP
127 月 (10 進数表記)。 (01\-12)
128 .TP 
129 \fB%M\fP
130 分 (10 進数表記) (00\-59)
131 .TP 
132 \fB%n\fP
133 改行。 (SU)
134 .TP 
135 \fB%O\fP
136 別形式を使用する際の修飾子。下記参照。 (SU)
137 .TP 
138 \fB%p\fP
139 現在のロケールにおける「午前」「午後」に相当する文字列。 英語の場合には "AM" または "PM" となる。
140 正午は「午後」、真夜中は「午前」として扱われる。
141 .TP 
142 \fB%P\fP
143 \fB%p\fP と同様であるが小文字が使用される。 英語の場合には "am" や "pm" となる。(GNU)
144 .TP 
145 \fB%r\fP
146 午前・午後形式での時刻。 POSIX ロケールでは \fB%I:%M:%S %p\fP と等価である。(SU)
147 .TP 
148 \fB%R\fP
149 The time in 24\-hour notation (\fB%H:%M\fP).  (SU)  For a version including the
150 seconds, see \fB%T\fP below.
151 .TP 
152 \fB%s\fP
153 紀元 (Epoch; 1970\-01\-01 00:00:00 +0000 (UTC)) からの秒数。 (TZ)
154 .TP 
155 \fB%S\fP
156 秒 (10 進数表記) (00\-60)  (時々ある閏秒に対応するため、値の範囲は 60 までとなっている)
157 .TP 
158 \fB%t\fP
159 タブ文字 (SU)
160 .TP 
161 \fB%T\fP
162 The time in 24\-hour notation (\fB%H:%M:%S\fP).  (SU)
163 .TP 
164 \fB%u\fP
165 週の何番目の日 (10 進数表記) か。月曜日を 1 とする (1\-7)。 \fB%w\fP も参照。(SU)
166 .TP 
167 \fB%U\fP
168 年の初めからの通算の週番号 (10 進数表記) (00\-53)。 その年の最初の日曜日を、第 1 週の始まりとして計算する。 \fB%V\fP と \fB%W\fP
169 も参照すること。
170 .TP 
171 \fB%V\fP
172 ISO\ 8601 形式での年の始めからの週番号 (「注意」の節を参照)。 10 進数表記で、01 から 53 の値となる。週番号は、
173 新しい年が少なくとも 4 日以上含まれる最初の週を 1 として計算する。 \fB%U\fP と \fB%W\fP も参照のこと。(SU)
174 .TP 
175 \fB%w\fP
176 週の何番目の日 (10 進数表記) か。日曜日を 0 とする。(0\-6)。 \fB%u\fP も参照。(SU)
177 .TP 
178 \fB%W\fP
179 年の初めからの通算の週番号 (10 進数表記) (00\-53)。 その年の最初の月曜日を、第 1 週の始まりとして計算する。
180 .TP 
181 \fB%x\fP
182 現在のロケールで一般的な日付表記。時刻は含まない。
183 .TP 
184 \fB%X\fP
185 現在のロケールで一般的な時刻表記。日付は含まない。
186 .TP 
187 \fB%y\fP
188 西暦の下2桁 (世紀部分を含まない年) (00\-99)。
189 .TP 
190 \fB%Y\fP
191 世紀部分を含めた ( 4 桁の) 西暦年。
192 .TP 
193 \fB%z\fP
194 \fI+hhmm\fP や \fI\-hhmm\fP の形式のタイムゾーン (UTC へのオフセット時間)。(SU)
195 .TP 
196 \fB%Z\fP
197 The timezone name or abbreviation.
198 .TP 
199 \fB%+\fP
200 .\" Nov 05 -- Not in Linux/glibc, but is in some BSDs (according to
201 .\" their man pages)
202 \fBdate\fP(1)  形式での日時。(TZ)  (glibc2 ではサポートされていない)
203 .TP 
204 \fB%%\fP
205 \(aq%\(aq 文字。
206 .PP
207 いくつかの変換指定では、変換指定文字の前に \fBE\fP や \fBO\fP 「修飾子」を置くことによって別書式を使用するように指定することができる。
208 現在のロケールにおいて別書式が存在しない場合には、 通常の変換指定が使用されたかのように動作する (SU)。 統一 UNIX 規格 (Single
209 UNIX Specification) では \fB%Ec\fP, \fB%EC\fP, \fB%Ex\fP, \fB%EX\fP, \fB%Ey\fP, \fB%EY\fP,
210 \fB%Od\fP, \fB%Oe\fP, \fB%OH\fP, \fB%OI\fP, \fB%Om\fP, \fB%OM\fP, \fB%OS\fP, \fB%Ou\fP, \fB%OU\fP,
211 \fB%OV\fP, \fB%Ow\fP, \fB%OW\fP, \fB%Oy\fP, について記述がある。ここで \fBO\fP 修飾子は別形式の数値 (ローマ数字とか)
212 を指定するために使用する。 \fBE\fP 修飾子はロケール依存の別表現を指定するのに使用する。 (訳注: \fBE\fP
213 修飾子は日本で使用されている「昭和」「平成」 などの元号による年表記を指定する。glibc 2.2 以降でのみ有効)
214 .PP
215 要素別の時刻構造体 \fItm\fP の詳細は \fI<time.h>\fP に定義されている。 \fBctime\fP(3)  も参照すること。
216 .SH 返り値
217 Provided that the result string, including the terminating null byte, does
218 not exceed \fImax\fP bytes, \fBstrftime\fP()  returns the number of bytes
219 (excluding the terminating null byte)  placed in the array \fIs\fP.  If the
220 length of the result string (including the terminating null byte)  would
221 exceed \fImax\fP bytes, then \fBstrftime\fP()  returns 0, and the contents of the
222 array are undefined.  (This behavior applies since at least libc 4.4.4; very
223 old versions of libc, such as libc 4.4.1, would return \fImax\fP if the array
224 was too small.)
225 .LP
226 Note that the return value 0 does not necessarily indicate an error.  For
227 example, in many locales \fB%p\fP yields an empty string.  An empty \fIformat\fP
228 string will likewise yield an empty string.
229 .SH 環境変数
230 環境変数 \fBTZ\fP と \fBLC_TIME\fP が使用される。 (訳注: \fBLC_ALL\fP が設定されている場合には \fBLC_TIME\fP
231 よりもそちらが優先される。 \fBLC_TIME\fP も \fBLC_ALL\fP も設定されていない場合には \fBLANG\fP が使用される。)
232 .SH 準拠
233 SVr4, C89, C99.  個々の変換が厳密にどの規格に含まれるかは、 ANSI C (印なし)、統一 UNIX 規格 (SU印)、Olson の
234 timezone パッケージ (TZ印)、 glibc 独自 (GNU印) で示している。glibc2 では \fB%+\fP はサポートされていないが、
235 いくつかの拡張が行われている。POSIX.1 では ANSI C のみを参照している。 POSIX.2 の \fBdate\fP(1)
236 のところに記述されている幾つかの拡張は \fBstrftime\fP()  にも適用できるだろう。 \fB%F\fP 変換は C99 と POSIX.1\-2001
237 にある。
238
239 SUSv2 では、 \fB%S\fP は 00 から 61 の範囲をとると規定されている。 これは、1分間のうち閏秒が 2つ入る可能性が理論的にはあることを
240 考慮してのものである (実際には、このような状況はこれまで一度も 起こっていない)。
241 .SH 注意
242 .SS "ISO\ 8601 の週・曜日表記 (Week Dates)"
243 \fB%G\fP, \fB%g\fP, and \fB%V\fP yield values calculated from the week\-based year
244 defined by the ISO\ 8601 standard.  In this system, weeks start on a Monday,
245 and are numbered from 01, for the first week, up to 52 or 53, for the last
246 week.  Week 1 is the first week where four or more days fall within the new
247 year (or, synonymously, week 01 is: the first week of the year that contains
248 a Thursday; or, the week that has 4 January in it).  When three of fewer
249 days of the first calendar week of the new year fall within that year, then
250 the ISO 8601 week\-based system counts those days as part of week 53 of the
251 preceding year.  For example, 1 January 2010 is a Friday, meaning that just
252 three days of that calendar week fall in 2010.  Thus, the ISO\ 8601
253 week\-based system considers these days to be part of week 53 (\fB%V\fP)  of the
254 year 2009 (\fB%G\fP); week 01 of ISO\ 8601 year 2010 starts on Monday, 4
255 January 2010.
256 .SS "glibc での注意"
257 .\" HP-UX and Tru64 also have features like this.
258 glibc では変換指定にいくつか拡張を行っている (これらの拡張は POSIX.1\-2001 には規定されていないが、
259 他のいくつかのシステムで同様の機能が提供されている)。 \(aq%\(aq 文字と変換指定文字の間に、オプションとして \fIflag\fP とフィールドの
260 \fI幅\fP を指定できる (これらを指定する場合には \fBE\fP や \fBO\fP 修飾子の前に置く)。
261
262 以下のフラグ文字が使用できる:
263 .TP 
264 \fB_\fP
265 (下線)  数値の結果文字列のパディング (穴埋め) をスペース (空白文字) で行う。
266 .TP 
267 \fB\-\fP
268 (ダッシュ)  数値の結果文字列に対するパディングを行わない。
269 .TP 
270 \fB0\fP
271 変換指定文字がデフォルトではスペースでパディングを行う場合でも、 数値の結果文字列へのパディングを 0 で行う。
272 .TP 
273 \fB^\fP
274 結果文字列中のアルファベット文字を大文字に変換する。
275 .TP 
276 \fB#\fP
277 結果文字列の大文字・小文字を入れ替える (このフラグは特定の変換指定文字でしか機能しない。その中でも 本当に有用なのは \fB%Z\fP の場合だけである)。
278 .PP
279 オプションの10進数の幅指定子はフラグの後ろに置くことができる (フラグはなくてもよい)。フィールドの本来の大きさが指定された幅よりも
280 小さい場合、結果文字列の左側は指定された幅までパディングされる。
281 .SH バグ
282 If the output string would exceed \fImax\fP bytes, \fIerrno\fP is \fInot\fP set.
283 This makes it impossible to distinguish this error case from cases where the
284 \fIformat\fP string legitimately produces a zero\-length output string.
285 POSIX.1\-2001 does \fInot\fP specify any \fIerrno\fP settings for \fBstrftime\fP().
286
287 \fBgcc\fP(1)  のいくつかのバージョンにはおかしなところがあり、 \fB%c\fP の使用法について以下のような警告を出す: \fIwarning:
288 `%c' yields only last 2 digits of year in some locales\fP
289 (\fI警告:\fPいくつかのロケールでは\fI`%c'\fPは年の下2桁しか出力しない\fI)。\fP もちろんプログラマが \fB%c\fP
290 を使うのはお薦めできることである。 \fB%c\fP を使うと適切な日付と時刻の表記を得ることができるからである。 \fBgcc\fP(1)
291 のこの問題を回避しようとすると、何かすっきりしない気分になるだろう。 比較的きれいな解決方法は以下のような中間関数を追加することである。
292 .in +4n
293 .nf
294
295 size_t
296 my_strftime(char *s, size_t max, const char *fmt,
297             const struct tm *tm)
298 {
299     return strftime(s, max, fmt, tm);
300 }
301 .fi
302 .in
303
304 現在では、 \fBgcc\fP(1)  はこの警告を抑えるための \fI\-Wno\-format\-y2k\fP オプションを
305 提供しており、上記の回避策はもはや必要ない。
306 .SH 例
307 \fBRFC\ 2822 準拠の日付形式\fP (%a と %b は英語ロケール)
308 .PP
309 .in +2n
310 "%a,\ %d\ %b\ %Y\ %T\ %z"
311 .PP
312 \fBRFC\ 822 準拠の日付形式\fP (%a と %b は英語ロケール)
313 .PP
314 .in +2n
315 "%a,\ %d\ %b\ %y\ %T\ %z"
316 .SS サンプルプログラム
317 以下のプログラムを使うと \fBstrftime\fP()  の実験ができる。
318 .PP
319 以下に、 \fBstrftime\fP()  の glibc 実装が生成する結果の例をいくつか示す:
320 .in +4n
321 .nf
322
323 $\fB ./a.out \(aq%m\(aq\fP
324 Result string is "11"
325 $\fB ./a.out \(aq%5m\(aq\fP
326 Result string is "00011"
327 $\fB ./a.out \(aq%_5m\(aq\fP
328 Result string is "   11"
329 .fi
330 .in
331 .PP
332 プログラムのソースは以下の通り:
333 .nf
334
335 #include <time.h>
336 #include <stdio.h>
337 #include <stdlib.h>
338
339 int
340 main(int argc, char *argv[])
341 {
342     char outstr[200];
343     time_t t;
344     struct tm *tmp;
345
346     t = time(NULL);
347     tmp = localtime(&t);
348     if (tmp == NULL) {
349         perror("localtime");
350         exit(EXIT_FAILURE);
351     }
352
353     if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) {
354         fprintf(stderr, "strftime returned 0");
355         exit(EXIT_FAILURE);
356     }
357
358     printf("Result string is \e"%s\e"\en", outstr);
359     exit(EXIT_SUCCESS);
360 }
361 .fi
362 .SH 関連項目
363 \fBdate\fP(1), \fBtime\fP(2), \fBctime\fP(3), \fBsetlocale\fP(3), \fBsprintf\fP(3),
364 \fBstrptime\fP(3)
365 .SH この文書について
366 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
367 である。プロジェクトの説明とバグ報告に関する情報は
368 http://www.kernel.org/doc/man\-pages/ に書かれている。