2008-09-07 04:11:07 +00:00
|
|
|
.\" Copyright 2001 walter harms (walter.harms@informatik.uni-oldenburg.de)
|
|
|
|
.\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
|
|
|
|
.\" <mtk.manpages@gmail.com>
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.\" Modified, 2001-12-26, aeb
|
2008-09-07 04:11:07 +00:00
|
|
|
.\" 2008-09-07, mtk, Various rewrites; added an example program.
|
|
|
|
.\"
|
_exit.2, brk.2, capget.2, chdir.2, chmod.2, chown.2, chroot.2, getdtablesize.2, gethostname.2, getpagesize.2, getsid.2, killpg.2, mknod.2, mknodat.2, poll.2, posix_fadvise.2, pread.2, readlink.2, setpgid.2, setreuid.2, sigaltstack.2, stat.2, symlink.2, sync.2, truncate.2, vfork.2, wait.2, wait4.2, a64l.3, abs.3, acos.3, acosh.3, asin.3, asinh.3, atan.3, atan2.3, atoi.3, cbrt.3, ceil.3, copysign.3, cosh.3, dirfd.3, div.3, ecvt.3, erf.3, erfc.3, exp.3, exp2.3, fabs.3, fdim.3, ffs.3, floor.3, fma.3, fmax.3, fmin.3, fmod.3, fpclassify.3, frexp.3, ftw.3, fwide.3, gcvt.3, getcwd.3, getdate.3, getgrent.3, gethostid.3, getpass.3, getpwent.3, getsubopt.3, getw.3, hypot.3, ilogb.3, index.3, isalpha.3, isgreater.3, iswblank.3, j0.3, ldexp.3, lockf.3, log.3, log10.3, log1p.3, logb.3, lrint.3, lround.3, mkstemp.3, mktemp.3, modf.3, mq_receive.3, mq_send.3, nan.3, nextafter.3, posix_fallocate.3, posix_memalign.3, printf.3, qecvt.3, random.3, realpath.3, remainder.3, remquo.3, rint.3, round.3, scalb.3, scalbln.3, scanf.3, siginterrupt.3, signbit.3, sigset.3, sinh.3, sqrt.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strfry.3, strpbrk.3, strsep.3, strspn.3, strstr.3, strtod.3, strtok.3, strtol.3, strtoul.3, strxfrm.3, tanh.3, tgamma.3, trunc.3, ttyslot.3, ualarm.3, usleep.3, wprintf.3, armscii-8.7, cp1251.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-3.7, iso_8859-5.7, iso_8859-6.7, iso_8859-8.7, koi8-u.7: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 17:19:13 +00:00
|
|
|
.TH GETDATE 3 2010-09-20 "" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
2008-09-07 04:11:07 +00:00
|
|
|
getdate, getdate_r \- convert a date-plus-time string to broken-down time
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.B "#include <time.h>"
|
|
|
|
.sp
|
2007-04-03 15:32:52 +00:00
|
|
|
.BI "struct tm *getdate(const char *" string );
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
2007-09-20 16:26:31 +00:00
|
|
|
.B "extern int getdate_err;"
|
2007-04-05 12:36:57 +00:00
|
|
|
.sp
|
2004-11-03 13:51:07 +00:00
|
|
|
.B "#include <time.h>"
|
|
|
|
.sp
|
2007-12-23 08:27:42 +00:00
|
|
|
.BI "int getdate_r(const char *" string ", struct tm *" res );
|
2010-09-18 08:40:04 +00:00
|
|
|
.sp
|
|
|
|
.in -4n
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
|
|
.BR feature_test_macros (7)):
|
|
|
|
.in
|
|
|
|
.sp
|
|
|
|
.BR getdate ():
|
|
|
|
.ad l
|
|
|
|
.RS 4
|
|
|
|
_XOPEN_SOURCE\ >=\ 500 ||
|
|
|
|
_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
|
|
|
|
.RE
|
|
|
|
.br
|
|
|
|
.BR getdate_r ():
|
|
|
|
.ad l
|
|
|
|
.RS 4
|
|
|
|
_GNU_SOURCE
|
|
|
|
.RE
|
|
|
|
.ad
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
|
|
|
The function
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getdate ()
|
2008-09-07 04:11:07 +00:00
|
|
|
converts a string representation of a date and time,
|
|
|
|
contained in the buffer pointed to by
|
|
|
|
.IR string ,
|
|
|
|
into a broken-down time.
|
|
|
|
The broken-down time is stored in a
|
2007-12-13 20:46:52 +00:00
|
|
|
.I tm
|
2008-09-07 04:11:07 +00:00
|
|
|
structure, and a pointer to this
|
|
|
|
structure is returned as the function result.
|
2007-12-13 20:46:52 +00:00
|
|
|
This
|
|
|
|
.I tm
|
2008-09-07 04:11:07 +00:00
|
|
|
structure is allocated in static storage,
|
|
|
|
and consequently it will be overwritten by further calls to
|
|
|
|
.BR getdate ().
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
In contrast to
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR strptime (3),
|
|
|
|
(which has a
|
|
|
|
.I format
|
|
|
|
argument),
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getdate ()
|
2004-11-03 13:51:07 +00:00
|
|
|
uses the formats found in the file
|
2008-09-07 04:11:07 +00:00
|
|
|
whose full pathname is given in the environment variable
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR DATEMSK .
|
|
|
|
The first line in the file that matches the given input string
|
|
|
|
is used for the conversion.
|
|
|
|
|
|
|
|
The matching is done case insensitively.
|
|
|
|
Superfluous whitespace, either in the pattern or in the string to
|
|
|
|
be converted, is ignored.
|
|
|
|
|
|
|
|
The conversion specifications that a pattern can contain are those given for
|
|
|
|
.BR strptime (3).
|
2008-09-07 04:11:07 +00:00
|
|
|
One more conversion specification is specified in POSIX.1-2001:
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %Z
|
|
|
|
Timezone name.
|
2008-09-07 04:11:07 +00:00
|
|
|
This is not implemented in glibc.
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
|
|
|
When
|
|
|
|
.B %Z
|
2008-09-07 04:11:07 +00:00
|
|
|
is given, the structure containing the broken-down time
|
|
|
|
is initialized with values corresponding to the current
|
2008-09-07 04:17:25 +00:00
|
|
|
time in the given timezone.
|
2008-09-07 04:11:07 +00:00
|
|
|
Otherwise, the structure is initialized to the broken-down time
|
|
|
|
corresponding to the current local time (as by a call to
|
|
|
|
.BR localtime (3)).
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
|
|
|
When only the weekday is given, the day is taken to be the first such day
|
|
|
|
on or after today.
|
|
|
|
.LP
|
|
|
|
When only the month is given (and no year), the month is taken to
|
|
|
|
be the first such month equal to or after the current month.
|
|
|
|
If no day is given, it is the first day of the month.
|
|
|
|
.LP
|
|
|
|
When no hour, minute and second are given, the current
|
|
|
|
hour, minute and second are taken.
|
|
|
|
.LP
|
|
|
|
If no date is given, but we know the hour, then that hour is taken
|
|
|
|
to be the first such hour equal to or after the current hour.
|
2008-09-07 04:11:07 +00:00
|
|
|
|
|
|
|
.BR getdate_r ()
|
|
|
|
is a GNU extension that provides a reentrant version of
|
|
|
|
.BR getdate ().
|
|
|
|
Rather than using a global variable to report errors and a static buffer
|
|
|
|
to return the broken down time,
|
|
|
|
it returns errors via the function result value,
|
|
|
|
and returns the resulting broken-down time in the
|
|
|
|
caller-allocated buffer pointed to by the argument
|
|
|
|
.IR res .
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "RETURN VALUE"
|
2008-09-10 12:39:34 +00:00
|
|
|
When successful,
|
2008-09-07 04:11:07 +00:00
|
|
|
.BR getdate ()
|
|
|
|
returns a pointer to a
|
2005-11-02 13:55:25 +00:00
|
|
|
.IR "struct tm" .
|
2004-11-03 13:51:07 +00:00
|
|
|
Otherwise, it returns NULL and sets the global variable
|
2008-09-07 04:11:07 +00:00
|
|
|
.IR getdate_err
|
|
|
|
to one of the error numbers shown below.
|
2004-11-03 13:51:07 +00:00
|
|
|
Changes to
|
|
|
|
.I errno
|
2007-04-12 22:42:49 +00:00
|
|
|
are unspecified.
|
2008-09-07 04:11:07 +00:00
|
|
|
|
|
|
|
On success
|
|
|
|
.BR getdate_r ()
|
|
|
|
returns 0;
|
|
|
|
on error it returns one of the error numbers shown below.
|
|
|
|
.SH ERRORS
|
|
|
|
The following errors are returned via
|
|
|
|
.IR getdate_err
|
|
|
|
(for
|
|
|
|
.BR getdate ())
|
|
|
|
or as the function result (for
|
|
|
|
.BR getdate_r ()):
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP 4n
|
|
|
|
.B 1
|
2007-06-22 19:42:52 +00:00
|
|
|
The
|
|
|
|
.B DATEMSK
|
2008-09-07 04:11:07 +00:00
|
|
|
environment variable is not defined, or its value is an empty string.
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B 2
|
2008-09-07 04:11:07 +00:00
|
|
|
The template file specified by
|
|
|
|
.B DATEMSK
|
|
|
|
cannot be opened for reading.
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B 3
|
|
|
|
Failed to get file status information.
|
2008-09-07 04:11:07 +00:00
|
|
|
.\" stat()
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B 4
|
|
|
|
The template file is not a regular file.
|
|
|
|
.TP
|
|
|
|
.B 5
|
2008-09-07 04:11:07 +00:00
|
|
|
An error was encountered while reading the template file.
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B 6
|
|
|
|
Memory allocation failed (not enough memory available).
|
2008-09-07 04:11:07 +00:00
|
|
|
.\" Error 6 doesn't seem to occur in glibc
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B 7
|
|
|
|
There is no line in the file that matches the input.
|
|
|
|
.TP
|
|
|
|
.B 8
|
|
|
|
Invalid input specification.
|
2007-05-19 04:30:20 +00:00
|
|
|
.SH ENVIRONMENT
|
|
|
|
.TP
|
|
|
|
.B DATEMSK
|
|
|
|
File containing format patterns.
|
|
|
|
.TP
|
|
|
|
.BR TZ ", " LC_TIME
|
|
|
|
Variables used by
|
|
|
|
.BR strptime (3).
|
|
|
|
.SH "CONFORMING TO"
|
2008-07-15 13:39:17 +00:00
|
|
|
POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NOTES
|
2006-08-03 13:57:30 +00:00
|
|
|
The POSIX.1-2001 specification for
|
2007-05-12 00:30:29 +00:00
|
|
|
.BR strptime (3)
|
2004-11-03 13:51:07 +00:00
|
|
|
contains conversion specifications using the
|
|
|
|
.B %E
|
|
|
|
or
|
|
|
|
.B %O
|
|
|
|
modifier, while such specifications are not given for
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getdate ().
|
2008-09-07 04:11:07 +00:00
|
|
|
In glibc,
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getdate ()
|
2008-09-07 04:11:07 +00:00
|
|
|
is implemented using
|
|
|
|
.BR strptime (3),
|
|
|
|
so that precisely the same conversions are supported by both.
|
|
|
|
.SH EXAMPLE
|
|
|
|
The program below calls
|
|
|
|
.BR getdate ()
|
|
|
|
for each of its command-line arguments,
|
|
|
|
and for each call displays the values in the fields of the returned
|
|
|
|
.I tm
|
|
|
|
structure.
|
|
|
|
The following shell session demonstrates the operation of the program:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " TFILE=$PWD/tfile"
|
|
|
|
.RB "$" " echo \(aq%A\(aq > $TFILE " " # Full weekday name"
|
|
|
|
.RB "$" " echo \(aq%T\(aq >> $TFILE" " # ISO date (YYYY-MM-DD)"
|
|
|
|
.RB "$" " echo \(aq%F\(aq >> $TFILE" " # Time (HH:MM:SS)"
|
|
|
|
.RB "$" " date"
|
|
|
|
.RB "$" " export DATEMSK=$TFILE"
|
|
|
|
.RB "$" " ./a.out Tuesday \(aq2009-12-28\(aq \(aq12:22:33\(aq"
|
2008-09-07 04:11:07 +00:00
|
|
|
Sun Sep 7 06:03:36 CEST 2008
|
|
|
|
Call 1 ("Tuesday") succeeded:
|
|
|
|
tm_sec = 36
|
|
|
|
tm_min = 3
|
|
|
|
tm_hour = 6
|
|
|
|
tm_mday = 9
|
|
|
|
tm_mon = 8
|
|
|
|
tm_year = 108
|
|
|
|
tm_wday = 2
|
|
|
|
tm_yday = 252
|
|
|
|
tm_isdst = 1
|
|
|
|
Call 2 ("2009-12-28") succeeded:
|
|
|
|
tm_sec = 36
|
|
|
|
tm_min = 3
|
|
|
|
tm_hour = 6
|
|
|
|
tm_mday = 28
|
|
|
|
tm_mon = 11
|
|
|
|
tm_year = 109
|
|
|
|
tm_wday = 1
|
|
|
|
tm_yday = 361
|
|
|
|
tm_isdst = 0
|
|
|
|
Call 3 ("12:22:33") succeeded:
|
|
|
|
tm_sec = 33
|
|
|
|
tm_min = 22
|
|
|
|
tm_hour = 12
|
|
|
|
tm_mday = 7
|
|
|
|
tm_mon = 8
|
|
|
|
tm_year = 108
|
|
|
|
tm_wday = 0
|
|
|
|
tm_yday = 250
|
|
|
|
tm_isdst = 1
|
|
|
|
.fi
|
|
|
|
.in
|
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strtol.3, core.5: global fix: Add ".SS Program source" to EXAMPLE
Add ".SS Program source" to clearly distinguish shell session and
descriptive text from actual program code.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:51:05 +00:00
|
|
|
.SS Program source
|
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getaddrinfo.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5: srcfix
s/\.R " "/\\\&/ as a way of getting a blank line after a .SS heading.
(Suggested by Sam Varshavchik <mrsam@courier-mta.com>)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-11-05 01:42:45 +00:00
|
|
|
\&
|
2008-09-07 04:11:07 +00:00
|
|
|
.nf
|
|
|
|
#define _GNU_SOURCE 500
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct tm *tmp;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 1; j < argc; j++) {
|
|
|
|
tmp = getdate(argv[j]);
|
|
|
|
|
|
|
|
if (tmp == NULL) {
|
|
|
|
printf("Call %d failed; getdate_err = %d\\n",
|
|
|
|
j, getdate_err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Call %d (\\"%s\\") succeeded:\\n", j, argv[j]);
|
|
|
|
printf(" tm_sec = %d\\n", tmp\->tm_sec);
|
|
|
|
printf(" tm_min = %d\\n", tmp\->tm_min);
|
|
|
|
printf(" tm_hour = %d\\n", tmp\->tm_hour);
|
|
|
|
printf(" tm_mday = %d\\n", tmp\->tm_mday);
|
|
|
|
printf(" tm_mon = %d\\n", tmp\->tm_mon);
|
|
|
|
printf(" tm_year = %d\\n", tmp\->tm_year);
|
|
|
|
printf(" tm_wday = %d\\n", tmp\->tm_wday);
|
|
|
|
printf(" tm_yday = %d\\n", tmp\->tm_yday);
|
|
|
|
printf(" tm_isdst = %d\\n", tmp\->tm_isdst);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
.fi
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
2007-06-01 06:26:06 +00:00
|
|
|
.BR time (2),
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR localtime (3),
|
2006-05-01 01:52:57 +00:00
|
|
|
.BR setlocale (3),
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR strftime (3),
|
|
|
|
.BR strptime (3),
|
2006-05-15 09:13:10 +00:00
|
|
|
.BR feature_test_macros (7)
|