GETDATE(3POSIX) | POSIX Programmer's Manual | GETDATE(3POSIX) |
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
getdate — convert user format date and time
#include <time.h>
struct tm *getdate(const char *string);
The getdate() function shall convert a string representation of a date or time into a broken-down time.
The external variable or macro getdate_err, which has type int, is used by getdate() to return error values. It is unspecified whether getdate_err is a macro or an identifier declared with external linkage, and whether or not it is a modifiable lvalue. If a macro definition is suppressed in order to access an actual object, or a program defines an identifier with the name getdate_err, the behavior is undefined.
Templates are used to parse and interpret the input string. The templates are contained in a text file identified by the environment variable DATEMSK. The DATEMSK variable should be set to indicate the full pathname of the file that contains the templates. The first line in the template that matches the input specification is used for interpretation and conversion into the internal time format.
The following conversion specifications shall be supported:
The match between the template and input specification performed by getdate() shall be case-insensitive.
The month and weekday names can consist of any combination of upper and lowercase letters. The process can request that the input date or time specification be in a specific language by setting the LC_TIME category (see setlocale()).
Leading zeros are not necessary for the descriptors that allow leading zeros. However, at most two digits are allowed for those descriptors, including leading zeros. Extra white space in either the template file or in string shall be ignored.
The results are undefined if the conversion specifications %c, %x, and %X include unsupported conversion specifications.
The following rules apply for converting the input specification into the internal format:
If a conversion specification in the DATEMSK file does not correspond to one of the conversion specifications above, the behavior is unspecified.
The getdate() function need not be thread-safe.
Upon successful completion, getdate() shall return a pointer to a struct tm. Otherwise, it shall return a null pointer and set getdate_err to indicate the error.
The getdate() function shall fail in the following cases, setting getdate_err to the value shown in the list below. Any changes to errno are unspecified.
The following sections are informative.
%m %A %B %d, %Y, %H:%M:%S %A %B %m/%d/%y %I %p %d,%m,%Y %H:%M at %A the %dst of %B in %Y run job at %I %p,%B %dnd %A den %d. %B %Y %H.%M Uhr
getdate("10/1/87 4 PM"); getdate("Friday"); getdate("Friday September 18, 1987, 10:30:30"); getdate("24,9,1986 10:30"); getdate("at monday the 1st of december in 1986"); getdate("run job at 3 PM, december 2nd");
If the LC_TIME category is set to a German locale that includes freitag as a weekday name and oktober as a month name, the following would be valid:
getdate("freitag den 10. oktober 1986 10.30 Uhr");
Invocation | Line in Template |
getdate("11/27/86") | %m/%d/%y |
getdate("27.11.86") | %d.%m.%y |
getdate("86-11-27") | %y-%m-%d |
getdate("Friday 12:00:00") | %A %H:%M:%S |
Input | Line in Template | Date |
Mon | %a | Mon Sep 22 12:19:47 EDT 1986 |
Sun | %a | Sun Sep 28 12:19:47 EDT 1986 |
Fri | %a | Fri Sep 26 12:19:47 EDT 1986 |
September | %B | Mon Sep 1 12:19:47 EDT 1986 |
January | %B | Thu Jan 1 12:19:47 EST 1987 |
December | %B | Mon Dec 1 12:19:47 EST 1986 |
Sep Mon | %b %a | Mon Sep 1 12:19:47 EDT 1986 |
Jan Fri | %b %a | Fri Jan 2 12:19:47 EST 1987 |
Dec Mon | %b %a | Mon Dec 1 12:19:47 EST 1986 |
Jan Wed 1989 | %b %a %Y | Wed Jan 4 12:19:47 EST 1989 |
Fri 9 | %a %H | Fri Sep 26 09:00:00 EDT 1986 |
Feb 10:30 | %b %H:%S | Sun Feb 1 10:00:30 EST 1987 |
10:30 | %H:%M | Tue Sep 23 10:30:00 EDT 1986 |
13:30 | %H:%M | Mon Sep 22 13:30:00 EDT 1986 |
Although historical versions of getdate() did not require that <time.h> declare the external variable getdate_err, this volume of POSIX.1‐2017 does require it. The standard developers encourage applications to remove declarations of getdate_err and instead incorporate the declaration by including <time.h>.
Applications should use %Y (4-digit years) in preference to %y (2-digit years).
In standard locales, the conversion specifications %c, %x, and %X do not include unsupported conversion specifiers and so the text regarding results being undefined is not a problem in that case.
None.
ctime(), localtime(), setlocale(), strftime(), times()
The Base Definitions volume of POSIX.1‐2017, <time.h>
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
2017 | IEEE/The Open Group |