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 2008-09-07 "" "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 "#define _XOPEN_SOURCE 500"
45 .B "#include <time.h>"
47 .BI "struct tm *getdate(const char *" string );
49 .B "extern int getdate_err;"
51 .B "#define _GNU_SOURCE"
53 .B "#include <time.h>"
55 .BI "int getdate_r(const char *" string ", struct tm *" res );
60 .\"O converts a string representation of a date and time,
61 .\"O contained in the buffer pointed to by
63 .\"O into a broken-down time.
67 ¤¬»Ø¤¹¥Ð¥Ã¥Õ¥¡¤Ë³ÊǼ¤µ¤ì¤¿Ê¸»úÎóɽ¸½¤ÎÆüÉդȻþ¹ï¤ò¡¢
68 Í×ÁÇÊ̤λþ¹ï (broken-down time) ¤ËÊÑ´¹¤¹¤ë¡£
69 .\"O The broken-down time is stored in a
71 .\"O structure, and a pointer to this
72 .\"O structure is returned as the function result.
75 .\"O structure is allocated in static storage,
76 .\"O and consequently it will be overwritten by further calls to
80 ¹½Â¤ÂΤ˳ÊǼ¤µ¤ì¡¢¤³¤Î¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤¬´Ø¿ô¤Î·ë²Ì¤È¤·¤ÆÊÖ¤µ¤ì¤ë¡£
83 ¹½Â¤ÂΤÏÀÅŪ¤Ê¥á¥â¥êÎΰè¤Ë¤¢¤ê¡¢
85 ¤Î¤½¤ì°Ê¹ß¤Î¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤¤µ¤ì¤ë¤«¤â¤µ¤ì¤Ê¤¤¡£
89 .\"O .BR strptime (3),
94 .\"O uses the formats found in the file
95 .\"O whose full pathname is given in the environment variable
97 .\"O The first line in the file that matches the given input string
98 .\"O is used for the conversion.
100 °ú¤¿ô¤Ç¥Õ¥©¡¼¥Þ¥Ã¥È¤ò»ØÄꤹ¤ë)
106 ¤Ç»ØÄꤵ¤ì¤¿¥Õ¥ë¥Ñ¥¹Ì¾¤Î¥Õ¥¡¥¤¥ë¤Ë½ñ¤¤¤Æ¤¢¤ë¥Õ¥©¡¼¥Þ¥Ã¥È¤òÍѤ¤¤ë¡£
109 .\"O The matching is done case insensitively.
110 .\"O Superfluous whitespace, either in the pattern or in the string to
111 .\"O be converted, is ignored.
112 ¥Þ¥Ã¥Á¤ÎºÝ¤Ë¤ÏÂçʸ»ú¾®Ê¸»ú¤ò¶èÊ̤·¤Ê¤¤¡£
113 ¥Ñ¥¿¡¼¥óÃæ¤Ç¤âÊÑ´¹¤µ¤ì¤ëʸ»úÎóÃæ¤Ç¤â¡¢Í¾Ê¬¤Ê¶õÇòʸ»ú¤Ï̵»ë¤µ¤ì¤ë¡£
116 .\"O The conversion specifications that a pattern can contain are those given for
117 .\"O .BR strptime (3).
118 .\"O One more conversion specification is specified in POSIX.1-2001:
119 ¥Ñ¥¿¡¼¥ó¤Ë»ØÄê¤Ç¤¤ëÊÑ´¹»ØÄê¤Ï¡¢
122 POSIX.1-2001 ¤Ç¤Ï°ì¤Ä¤ÎÊÑ´¹»ØÄ꤬Äɲäǵ¬Äꤵ¤ì¤Æ¤¤¤ë¡£
126 .\"O This is not implemented in glibc.
128 glibc ¤Ç¤Ï¼ÂÁõ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
132 .\"O is given, the structure containing the broken-down time
133 .\"O is initialized with values corresponding to the current
134 .\"O time in the given timezone.
135 .\"O Otherwise, the structure is initialized to the broken-down time
136 .\"O corresponding to the current local time (as by a call to
137 .\"O .BR localtime (3)).
139 ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢Í×ÁÇÊ̤λþ¹ï¤ò³ÊǼ¤¹¤ë¹½Â¤ÂΤϡ¢
140 »ØÄꤵ¤ì¤¿¥¿¥¤¥à¥¾¡¼¥ó¤Ë¤ª¤±¤ë¸½ºß»þ¹ï¤ËÂбþ¤¹¤ëÃͤǽé´ü²½¤µ¤ì¤ë¡£
141 »ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢¤³¤Î¹½Â¤ÂΤϸ½ºß¤Î¥í¡¼¥«¥ë¥¿¥¤¥à¤ËÂбþ¤¹¤ë
142 Í×ÁÇÊ̤λþ¹ï¤Ç½é´ü²½¤µ¤ì¤ë
144 ¤ò¸Æ¤Ó½Ð¤·¤¿¾ì¹ç¤ÈƱ¤¸)¡£
146 .\"O When only the weekday is given, the day is taken to be the first such day
147 .\"O on or after today.
148 ÍËÆü¤À¤±¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
149 º£Æü¤Þ¤¿¤Ïº£Æü°Ê¹ß¤Ç¡¢
150 ¤½¤ÎÍËÆü¤Ë¹çÃפ¹¤ëºÇ½é¤ÎÆü¤¬ºÎÍѤµ¤ì¤ë¡£
152 .\"O When only the month is given (and no year), the month is taken to
153 .\"O be the first such month equal to or after the current month.
154 .\"O If no day is given, it is the first day of the month.
155 (ǯ¤Ê¤·¤Ç) ·î¤À¤±¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
156 º£·î¤Þ¤¿¤Ïº£·î°Ê¹ß¤Ç¡¢
157 ¤½¤Î·î¤Ë¹çÃפ¹¤ëºÇ½é¤Î·î¤¬ºÎÍѤµ¤ì¤ë¡£
159 .\"O When no hour, minute and second are given, the current
160 .\"O hour, minute and second are taken.
161 »þ¡¦Ê¬¡¦É䬤¤¤º¤ì¤â»ØÄꤵ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
162 ¸½ºß¤Î»þ¡¦Ê¬¡¦É䬺ÎÍѤµ¤ì¤ë¡£
164 .\"O If no date is given, but we know the hour, then that hour is taken
165 .\"O to be the first such hour equal to or after the current hour.
166 ÆüÉդλØÄ꤬¤Ê¤«¤Ã¤¿¤¬¡¢»þ´Ö (hour) ¤À¤±»ØÄꤵ¤ì¤¿¾ì¹ç¤Ï¡¢
167 ¸½ºß¤Î»þ´Ö¤Þ¤¿¤Ï¤½¤ì°Ê¹ß¤Ç¡¢¤½¤Î»ØÄê¤Ë¹çÃפ¹¤ëºÇ½é¤Î»þ´Ö¤¬ºÎÍѤµ¤ì¤ë¡£
169 .\"O .BR getdate_r ()
170 .\"O is a GNU extension that provides a reentrant version of
172 .\"O Rather than using a global variable to report errors and a static buffer
173 .\"O to return the broken down time,
174 .\"O it returns errors via the function result value,
175 .\"O and returns the resulting broken-down time in the
176 .\"O caller-allocated buffer pointed to by the argument
181 ¤Î¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤòÄ󶡤·¤Æ¤¤¤ë¡£
183 ¤Ç¤Ï¡¢¥¨¥é¡¼¤òÊó¹ð¤¹¤ë¤Î¤Ë¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò»ÈÍѤ·¤¿¤ê¡¢
184 Í×ÁÇÊ̤λþ¹ï¤òÊÖ¤¹¤Î¤ËÀÅŪ¤Ê¥Ð¥Ã¥Õ¥¡¤ò»ÈÍѤ·¤¿¤ê¤»¤º¡¢
185 ¥¨¥é¡¼¤ò´Ø¿ô¤ÎÊÖ¤êÃÍ·Ðͳ¤ÇÊó¹ð¤·¡¢Í×ÁÇÊ̤λþ¹ï¤ò
188 ¤¬»Ø¤·¼¨¤¹¸Æ¤Ó½Ð¤·Â¦¤Ç³ä¤êÅö¤Æ¤¿¥Ð¥Ã¥Õ¥¡¤Ë³ÊǼ¤·¤ÆÊÖ¤¹¡£
189 .\"O .SH "RETURN VALUE"
191 .\"O When successful,
193 .\"O returns a pointer to a
194 .\"O .IR "struct tm" .
195 .\"O Otherwise, it returns NULL and sets the global variable
197 .\"O to one of the error numbers shown below.
200 .\"O are unspecified.
206 ¼ºÇÔ¤¹¤ë¤È NULL ¤òÊÖ¤·¡¢¥°¥í¡¼¥Ð¥ëÊÑ¿ô
208 ¤Ë°Ê²¼¤Ë¼¨¤¹¥¨¥é¡¼ÈÖ¹æ¤Î¤¤¤º¤ì¤«°ì¤Ä¤òÀßÄꤹ¤ë¡£
210 ¤ÎÊѹ¹¤Ë¤Ä¤¤¤Æ¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
213 .\"O .BR getdate_r ()
215 .\"O on error it returns one of the error numbers shown below.
219 ¼ºÇÔ¤¹¤ë¤È¡¢°Ê²¼¤Ë¼¨¤¹¥¨¥é¡¼ÈÖ¹æ¤Î¤¤¤º¤ì¤«°ì¤Ä¤òÊÖ¤¹¡£
222 .\"O The following errors are returned via
226 .\"O or as the function result (for
227 .\"O .BR getdate_r ()):
234 ¤Ç¤Ï) ´Ø¿ô¤ÎÊÖ¤êÃͤȤ·¤ÆÊÖ¤µ¤ì¤ë¡£
239 .\"O environment variable is not defined, or its value is an empty string.
242 ¤¬Ì¤ÄêµÁ¡¢¤Þ¤¿¤Ï¤½¤ÎÃͤ¬¶õʸ»úÎó¤Ç¤¢¤ë¡£
245 .\"O The template file specified by
247 .\"O cannot be opened for reading.
249 ¤Ç»ØÄꤵ¤ì¤¿¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ßÍѤ˥ª¡¼¥×¥ó¤Ç¤¤Ê¤¤¡£
252 .\"O Failed to get file status information.
253 ¥Õ¥¡¥¤¥ë¤Î¥¹¥Æ¡¼¥¿¥¹¾ðÊ󤬼èÆÀ¤Ç¤¤Ê¤¤¡£
257 .\"O The template file is not a regular file.
258 ¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤¬Ä̾ï¤Î¥Õ¥¡¥¤¥ë¤Ç¤Ê¤¤¡£
261 .\"O An error was encountered while reading the template file.
262 ¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ßÃæ¤Ë¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¡£
265 .\"O Memory allocation failed (not enough memory available).
266 .\"O .\" Error 6 doesn't seem to occur in glibc
267 ¥á¥â¥ê¤Î³ä¤êÅö¤Æ¤Ë¼ºÇÔ¤·¤¿ (¥á¥â¥ê¤¬Â¤ê¤Ê¤¤)¡£
268 .\" ¥¨¥é¡¼ 6 ¤Ï glibc ¤Ç¤ÏȯÀ¸¤·¤Ê¤¤¤è¤¦¤Ë¸«¤¨¤ë¡£
271 .\"O There is no line in the file that matches the input.
272 ÆþÎϤ˥ޥåÁ¤·¤¿¥Õ¥¡¥¤¥ë¤Ë¡¢¹Ô¤¬´Þ¤Þ¤ì¤Æ¤¤¤Ê¤¤¡£
275 .\"O Invalid input specification.
276 ÆþÎÏ»ØÄ꤬Àµ¤·¤¯¤Ê¤¤¡£
281 .\"O File containing format patterns.
282 ½ñ¼°¥Ñ¥¿¡¼¥ó¤ò´Þ¤à¥Õ¥¡¥¤¥ë¡£
285 .\"O Variables used by
286 .\"O .BR strptime (3).
289 .\"O .SH "CONFORMING TO"
294 .\"O The POSIX.1-2001 specification for
295 .\"O .BR strptime (3)
296 .\"O contains conversion specifications using the
300 .\"O modifier, while such specifications are not given for
304 .\"O is implemented using
305 .\"O .BR strptime (3),
306 .\"O so that precisely the same conversions are supported by both.
307 POSIX.1-2001 »ÅÍͤǤϡ¢
313 ¤È¤¤¤Ã¤¿½¤Àµ»Ò¤òÍѤ¤¤¿ÊÑ´¹»ØÄê¤òµ¬Äꤷ¤Æ¤¤¤ë¤¬¡¢
315 ¤Ë¤Ä¤¤¤Æ¤Ï¤³¤Î¤è¤¦¤Ê½¤¾þ»Ò¤Îµ¬Äê¤Ï¤Ê¤¤¡£
320 ¤òÍѤ¤¤Æ¼ÂÁõ¤µ¤ì¤Æ¤ª¤ê¡¢
321 ξ¼Ô¤Ç¤ÏÁ´¤¯Æ±¤¸ÊÑ´¹¤¬Î¾¼Ô¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
324 .\"O The program below calls
326 .\"O for each of its command-line arguments,
327 .\"O and for each call displays the values in the fields of the returned
330 .\"O The following shell session demonstrates the operation of the program:
331 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤¿ô¤Î¤½¤ì¤¾¤ì¤Ë¤Ä¤¤¤Æ
333 ¤ò¸Æ¤Ó½Ð¤·¡¢¤½¤ì¤¾¤ì¤Ë¤Ä¤¤¤ÆÊÖ¤µ¤ì¤¿
335 ¹½Â¤ÂΤΥե£¡¼¥ë¥ÉÃͤòɽ¼¨¤¹¤ë¡£
336 ¼¡¤Î¥·¥§¥ë¡¦¥»¥Ã¥·¥ç¥ó¤Ï¡¢¥×¥í¥°¥é¥à¤ÎÆ°ºîÎã¤Ç¤¢¤ë¡£
340 .RB "$" " TFILE=$PWD/tfile"
341 .RB "$" " echo \(aq%A\(aq > $TFILE " " # Full weekday name"
342 .RB "$" " echo \(aq%T\(aq >> $TFILE" " # ISO date (YYYY-MM-DD)"
343 .RB "$" " echo \(aq%F\(aq >> $TFILE" " # Time (HH:MM:SS)"
345 .RB "$" " export DATEMSK=$TFILE"
346 .RB "$" " ./a.out Tuesday \(aq2009-12-28\(aq \(aq12:22:33\(aq"
347 Sun Sep 7 06:03:36 CEST 2008
348 Call 1 ("Tuesday") succeeded:
358 Call 2 ("2009-12-28") succeeded:
368 Call 3 ("12:22:33") succeeded:
380 .\"O .SS Program source
381 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
384 #define _GNU_SOURCE 500
390 main(int argc, char *argv[])
395 for (j = 1; j < argc; j++) {
396 tmp = getdate(argv[j]);
399 printf("Call %d failed; getdate_err = %d\\n",
404 printf("Call %d (\\"%s\\") succeeded:\\n", j, argv[j]);
405 printf(" tm_sec = %d\\n", tmp\->tm_sec);
406 printf(" tm_min = %d\\n", tmp\->tm_min);
407 printf(" tm_hour = %d\\n", tmp\->tm_hour);
408 printf(" tm_mday = %d\\n", tmp\->tm_mday);
409 printf(" tm_mon = %d\\n", tmp\->tm_mon);
410 printf(" tm_year = %d\\n", tmp\->tm_year);
411 printf(" tm_wday = %d\\n", tmp\->tm_wday);
412 printf(" tm_yday = %d\\n", tmp\->tm_yday);
413 printf(" tm_isdst = %d\\n", tmp\->tm_isdst);
426 .BR feature_test_macros (7)