1 .\" Copyright 2001 walter harms (walter.harms@informatik.uni-oldenburg.de)
2 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Modified, 2001-12-26, aeb
26 .\" 2008-09-07, mtk, Various rewrites; added an example program.
28 .\" Japanese Version Copyright (c) 2002 NAKANO Takeo
29 .\" and Copyright (c) 2008, Akihiro MOTOKI all rights reserved.
31 .\" Translated 2002-01-12, NAKANO Takeo <nakano@apm.seikei.ac.jp>
32 .\" Updated 2008-09-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.09
34 .\"WORD: broken-down time 要素別の時刻
36 .TH GETDATE 3 2010-09-20 "" "Linux Programmer's Manual"
39 .\"O getdate, getdate_r \- convert a date-plus-time string to broken-down time
40 getdate, getdate_r \- 日付と時刻の文字列を要素別の時刻に変換する
43 .B "#include <time.h>"
45 .BI "struct tm *getdate(const char *" string );
47 .B "extern int getdate_err;"
49 .B "#include <time.h>"
51 .BI "int getdate_r(const char *" string ", struct tm *" res );
54 .\"O Feature Test Macro Requirements for glibc (see
55 .\"O .BR feature_test_macros (7)):
57 .RB ( feature_test_macros (7)
64 _XOPEN_SOURCE\ >=\ 500 ||
65 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
78 .\"O converts a string representation of a date and time,
79 .\"O contained in the buffer pointed to by
81 .\"O into a broken-down time.
85 が指すバッファに格納された文字列表現の日付と時刻を、
86 要素別の時刻 (broken-down time) に変換する。
87 .\"O The broken-down time is stored in a
89 .\"O structure, and a pointer to this
90 .\"O structure is returned as the function result.
93 .\"O structure is allocated in static storage,
94 .\"O and consequently it will be overwritten by further calls to
98 構造体に格納され、この構造体へのポインタが関数の結果として返される。
103 のそれ以降の呼び出しで上書きされるかもされない。
107 .\"O .BR strptime (3),
112 .\"O uses the formats found in the file
113 .\"O whose full pathname is given in the environment variable
115 .\"O The first line in the file that matches the given input string
116 .\"O is used for the conversion.
124 で指定されたフルパス名のファイルに書いてあるフォーマットを用いる。
127 .\"O The matching is done case insensitively.
128 .\"O Superfluous whitespace, either in the pattern or in the string to
129 .\"O be converted, is ignored.
131 パターン中でも変換される文字列中でも、余分な空白文字は無視される。
134 .\"O The conversion specifications that a pattern can contain are those given for
135 .\"O .BR strptime (3).
136 .\"O One more conversion specification is specified in POSIX.1-2001:
140 POSIX.1-2001 では一つの変換指定が追加で規定されている。
144 .\"O This is not implemented in glibc.
150 .\"O is given, the structure containing the broken-down time
151 .\"O is initialized with values corresponding to the current
152 .\"O time in the given timezone.
153 .\"O Otherwise, the structure is initialized to the broken-down time
154 .\"O corresponding to the current local time (as by a call to
155 .\"O .BR localtime (3)).
157 が指定された場合、要素別の時刻を格納する構造体は、
158 指定されたタイムゾーンにおける現在時刻に対応する値で初期化される。
159 指定されていない場合、この構造体は現在のローカルタイムに対応する
164 .\"O When only the weekday is given, the day is taken to be the first such day
165 .\"O on or after today.
170 .\"O When only the month is given (and no year), the month is taken to
171 .\"O be the first such month equal to or after the current month.
172 .\"O If no day is given, it is the first day of the month.
177 .\"O When no hour, minute and second are given, the current
178 .\"O hour, minute and second are taken.
179 時・分・秒がいずれも指定されなかった場合、
182 .\"O If no date is given, but we know the hour, then that hour is taken
183 .\"O to be the first such hour equal to or after the current hour.
184 日付の指定がなかったが、時間 (hour) だけ指定された場合は、
185 現在の時間またはそれ以降で、その指定に合致する最初の時間が採用される。
187 .\"O .BR getdate_r ()
188 .\"O is a GNU extension that provides a reentrant version of
190 .\"O Rather than using a global variable to report errors and a static buffer
191 .\"O to return the broken down time,
192 .\"O it returns errors via the function result value,
193 .\"O and returns the resulting broken-down time in the
194 .\"O caller-allocated buffer pointed to by the argument
201 では、エラーを報告するのにグローバル変数を使用したり、
202 要素別の時刻を返すのに静的なバッファを使用したりせず、
203 エラーを関数の返り値経由で報告し、要素別の時刻を
206 が指し示す呼び出し側で割り当てたバッファに格納して返す。
207 .\"O .SH "RETURN VALUE"
209 .\"O When successful,
211 .\"O returns a pointer to a
212 .\"O .IR "struct tm" .
213 .\"O Otherwise, it returns NULL and sets the global variable
215 .\"O to one of the error numbers shown below.
218 .\"O are unspecified.
224 失敗すると NULL を返し、グローバル変数
226 に以下に示すエラー番号のいずれか一つを設定する。
231 .\"O .BR getdate_r ()
233 .\"O on error it returns one of the error numbers shown below.
237 失敗すると、以下に示すエラー番号のいずれか一つを返す。
240 .\"O The following errors are returned via
244 .\"O or as the function result (for
245 .\"O .BR getdate_r ()):
257 .\"O environment variable is not defined, or its value is an empty string.
263 .\"O The template file specified by
265 .\"O cannot be opened for reading.
267 で指定されたテンプレートファイルを読み込み用にオープンできない。
270 .\"O Failed to get file status information.
275 .\"O The template file is not a regular file.
276 テンプレートファイルが通常のファイルでない。
279 .\"O An error was encountered while reading the template file.
280 テンプレートファイルの読み込み中にエラーが起こった。
283 .\"O Memory allocation failed (not enough memory available).
284 .\"O .\" Error 6 doesn't seem to occur in glibc
285 メモリの割り当てに失敗した (メモリが足りない)。
286 .\" エラー 6 は glibc では発生しないように見える。
289 .\"O There is no line in the file that matches the input.
290 入力にマッチしたファイルに、行が含まれていない。
293 .\"O Invalid input specification.
299 .\"O File containing format patterns.
303 .\"O Variables used by
304 .\"O .BR strptime (3).
307 .\"O .SH "CONFORMING TO"
312 .\"O The POSIX.1-2001 specification for
313 .\"O .BR strptime (3)
314 .\"O contains conversion specifications using the
318 .\"O modifier, while such specifications are not given for
322 .\"O is implemented using
323 .\"O .BR strptime (3),
324 .\"O so that precisely the same conversions are supported by both.
331 といった修正子を用いた変換指定を規定しているが、
339 両者では全く同じ変換が両者でサポートされている。
342 .\"O The program below calls
344 .\"O for each of its command-line arguments,
345 .\"O and for each call displays the values in the fields of the returned
348 .\"O The following shell session demonstrates the operation of the program:
349 以下のプログラムは、コマンドライン引き数のそれぞれについて
354 次のシェル・セッションは、プログラムの動作例である。
358 .RB "$" " TFILE=$PWD/tfile"
359 .RB "$" " echo \(aq%A\(aq > $TFILE " " # Full weekday name"
360 .RB "$" " echo \(aq%T\(aq >> $TFILE" " # ISO date (YYYY-MM-DD)"
361 .RB "$" " echo \(aq%F\(aq >> $TFILE" " # Time (HH:MM:SS)"
363 .RB "$" " export DATEMSK=$TFILE"
364 .RB "$" " ./a.out Tuesday \(aq2009-12-28\(aq \(aq12:22:33\(aq"
365 Sun Sep 7 06:03:36 CEST 2008
366 Call 1 ("Tuesday") succeeded:
376 Call 2 ("2009-12-28") succeeded:
386 Call 3 ("12:22:33") succeeded:
398 .\"O .SS Program source
402 #define _GNU_SOURCE 500
408 main(int argc, char *argv[])
413 for (j = 1; j < argc; j++) {
414 tmp = getdate(argv[j]);
417 printf("Call %d failed; getdate_err = %d\\n",
422 printf("Call %d (\\"%s\\") succeeded:\\n", j, argv[j]);
423 printf(" tm_sec = %d\\n", tmp\->tm_sec);
424 printf(" tm_min = %d\\n", tmp\->tm_min);
425 printf(" tm_hour = %d\\n", tmp\->tm_hour);
426 printf(" tm_mday = %d\\n", tmp\->tm_mday);
427 printf(" tm_mon = %d\\n", tmp\->tm_mon);
428 printf(" tm_year = %d\\n", tmp\->tm_year);
429 printf(" tm_wday = %d\\n", tmp\->tm_wday);
430 printf(" tm_yday = %d\\n", tmp\->tm_yday);
431 printf(" tm_isdst = %d\\n", tmp\->tm_isdst);