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)):
56 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
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 ¹½Â¤ÂΤ˳ÊǼ¤µ¤ì¡¢¤³¤Î¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤¬´Ø¿ô¤Î·ë²Ì¤È¤·¤ÆÊÖ¤µ¤ì¤ë¡£
101 ¹½Â¤ÂΤÏÀÅŪ¤Ê¥á¥â¥êÎΰè¤Ë¤¢¤ê¡¢
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.
118 °ú¤¿ô¤Ç¥Õ¥©¡¼¥Þ¥Ã¥È¤ò»ØÄꤹ¤ë)
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.
130 ¥Þ¥Ã¥Á¤ÎºÝ¤Ë¤ÏÂçʸ»ú¾®Ê¸»ú¤ò¶èÊ̤·¤Ê¤¤¡£
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:
137 ¥Ñ¥¿¡¼¥ó¤Ë»ØÄê¤Ç¤¤ëÊÑ´¹»ØÄê¤Ï¡¢
140 POSIX.1-2001 ¤Ç¤Ï°ì¤Ä¤ÎÊÑ´¹»ØÄ꤬Äɲäǵ¬Äꤵ¤ì¤Æ¤¤¤ë¡£
144 .\"O This is not implemented in glibc.
146 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 »ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢¤³¤Î¹½Â¤ÂΤϸ½ºß¤Î¥í¡¼¥«¥ë¥¿¥¤¥à¤ËÂбþ¤¹¤ë
160 Í×ÁÇÊ̤λþ¹ï¤Ç½é´ü²½¤µ¤ì¤ë
162 ¤ò¸Æ¤Ó½Ð¤·¤¿¾ì¹ç¤ÈƱ¤¸)¡£
164 .\"O When only the weekday is given, the day is taken to be the first such day
165 .\"O on or after today.
166 ÍËÆü¤À¤±¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
167 º£Æü¤Þ¤¿¤Ïº£Æü°Ê¹ß¤Ç¡¢
168 ¤½¤ÎÍËÆü¤Ë¹çÃפ¹¤ëºÇ½é¤ÎÆü¤¬ºÎÍѤµ¤ì¤ë¡£
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.
173 (ǯ¤Ê¤·¤Ç) ·î¤À¤±¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
174 º£·î¤Þ¤¿¤Ïº£·î°Ê¹ß¤Ç¡¢
175 ¤½¤Î·î¤Ë¹çÃפ¹¤ëºÇ½é¤Î·î¤¬ºÎÍѤµ¤ì¤ë¡£
177 .\"O When no hour, minute and second are given, the current
178 .\"O hour, minute and second are taken.
179 »þ¡¦Ê¬¡¦É䬤¤¤º¤ì¤â»ØÄꤵ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
180 ¸½ºß¤Î»þ¡¦Ê¬¡¦É䬺ÎÍѤµ¤ì¤ë¡£
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
199 ¤Î¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤòÄ󶡤·¤Æ¤¤¤ë¡£
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 ¤Ë°Ê²¼¤Ë¼¨¤¹¥¨¥é¡¼ÈÖ¹æ¤Î¤¤¤º¤ì¤«°ì¤Ä¤òÀßÄꤹ¤ë¡£
228 ¤ÎÊѹ¹¤Ë¤Ä¤¤¤Æ¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
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 ()):
252 ¤Ç¤Ï) ´Ø¿ô¤ÎÊÖ¤êÃͤȤ·¤ÆÊÖ¤µ¤ì¤ë¡£
257 .\"O environment variable is not defined, or its value is an empty string.
260 ¤¬Ì¤ÄêµÁ¡¢¤Þ¤¿¤Ï¤½¤ÎÃͤ¬¶õʸ»úÎó¤Ç¤¢¤ë¡£
263 .\"O The template file specified by
265 .\"O cannot be opened for reading.
267 ¤Ç»ØÄꤵ¤ì¤¿¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ßÍѤ˥ª¡¼¥×¥ó¤Ç¤¤Ê¤¤¡£
270 .\"O Failed to get file status information.
271 ¥Õ¥¡¥¤¥ë¤Î¥¹¥Æ¡¼¥¿¥¹¾ðÊ󤬼èÆÀ¤Ç¤¤Ê¤¤¡£
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.
294 ÆþÎÏ»ØÄ꤬Àµ¤·¤¯¤Ê¤¤¡£
299 .\"O File containing format patterns.
300 ½ñ¼°¥Ñ¥¿¡¼¥ó¤ò´Þ¤à¥Õ¥¡¥¤¥ë¡£
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.
325 POSIX.1-2001 »ÅÍͤǤϡ¢
331 ¤È¤¤¤Ã¤¿½¤Àµ»Ò¤òÍѤ¤¤¿ÊÑ´¹»ØÄê¤òµ¬Äꤷ¤Æ¤¤¤ë¤¬¡¢
333 ¤Ë¤Ä¤¤¤Æ¤Ï¤³¤Î¤è¤¦¤Ê½¤¾þ»Ò¤Îµ¬Äê¤Ï¤Ê¤¤¡£
338 ¤òÍѤ¤¤Æ¼ÂÁõ¤µ¤ì¤Æ¤ª¤ê¡¢
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 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤¿ô¤Î¤½¤ì¤¾¤ì¤Ë¤Ä¤¤¤Æ
351 ¤ò¸Æ¤Ó½Ð¤·¡¢¤½¤ì¤¾¤ì¤Ë¤Ä¤¤¤ÆÊÖ¤µ¤ì¤¿
353 ¹½Â¤ÂΤΥե£¡¼¥ë¥ÉÃͤòɽ¼¨¤¹¤ë¡£
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
399 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
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);