2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
|
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
|
|
|
.\" References consulted:
|
|
|
|
.\" Linux libc source code
|
|
|
|
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
|
|
|
|
.\" 386BSD man pages
|
|
|
|
.\" GNU texinfo documentation on glibc date/time functions.
|
|
|
|
.\" Modified Sat Jul 24 18:03:44 1993 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Applied fix by Wolfgang Franke, aeb, 961011
|
|
|
|
.\" Corrected return value, aeb, 970307
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
.\" Added Single UNIX Spec conversions and %z, aeb/esr, 990329.
|
2007-05-18 10:30:02 +00:00
|
|
|
.\" 2005-11-22 mtk, added Glibc Notes covering optional 'flag' and
|
2005-11-23 09:01:15 +00:00
|
|
|
.\" 'width' components of conversion specifications.
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
2010-01-16 18:23:49 +00:00
|
|
|
.TH STRFTIME 3 2010-01-17 "GNU" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
strftime \- format date and time
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <time.h>
|
|
|
|
.sp
|
|
|
|
.BI "size_t strftime(char *" s ", size_t " max ", const char *" format ,
|
2007-04-03 15:32:52 +00:00
|
|
|
.BI " const struct tm *" tm );
|
2004-11-03 13:51:07 +00:00
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR strftime ()
|
|
|
|
function formats the broken-down time \fItm\fP
|
2004-11-03 13:51:07 +00:00
|
|
|
according to the format specification \fIformat\fP and places the
|
|
|
|
result in the character array \fIs\fP of size \fImax\fP.
|
2008-10-22 04:05:06 +00:00
|
|
|
.\" FIXME POSIX says: Local timezone information is used as though
|
|
|
|
.\" strftime() called tzset(). But this doesn't appear to be the case
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2010-01-17 04:02:38 +00:00
|
|
|
The format specification is a null-terminated string and may contain
|
|
|
|
special character sequences called
|
|
|
|
.IR "conversion specifications",
|
|
|
|
each of which is introduced by a \(aq%\(aq character and terminated by
|
|
|
|
some other character known as a
|
|
|
|
.IR "conversion specifier character".
|
|
|
|
All other character sequences are
|
|
|
|
.IR "ordinary character sequences".
|
|
|
|
.PP
|
|
|
|
The characters of ordinary character sequences (including the null byte)
|
|
|
|
are copied verbatim from \fIformat\fP to \fIs\fP. However, the characters
|
|
|
|
of conversion specifications are replaced as follows:
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %a
|
|
|
|
The abbreviated weekday name according to the current locale.
|
|
|
|
.TP
|
|
|
|
.B %A
|
|
|
|
The full weekday name according to the current locale.
|
|
|
|
.TP
|
|
|
|
.B %b
|
|
|
|
The abbreviated month name according to the current locale.
|
|
|
|
.TP
|
|
|
|
.B %B
|
|
|
|
The full month name according to the current locale.
|
|
|
|
.TP
|
|
|
|
.B %c
|
|
|
|
The preferred date and time representation for the current locale.
|
|
|
|
.TP
|
|
|
|
.B %C
|
|
|
|
The century number (year/100) as a 2-digit integer. (SU)
|
|
|
|
.TP
|
|
|
|
.B %d
|
|
|
|
The day of the month as a decimal number (range 01 to 31).
|
|
|
|
.TP
|
|
|
|
.B %D
|
2007-07-09 21:02:59 +00:00
|
|
|
Equivalent to
|
|
|
|
.BR %m/%d/%y .
|
intro.1, fork.2, futex.2, open.2, rename.2, select_tut.2, semop.2, spu_create.2, stat.2, netlink.3, random.3, scanf.3, shm_open.3, strftime.3, console.4, console_codes.4, sk98lin.4, st.4, bootparam.7, cpuset.7, credentials.7, man-pages.7, path_resolution.7, uri.7: Global fix: remove spaces around em-dash
Normal English typographical convention is not to have
spaces around em dashes.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2011-10-03 06:47:35 +00:00
|
|
|
(Yecch\(emfor Americans only.
|
2007-07-09 21:02:59 +00:00
|
|
|
Americans should note that in other countries
|
2007-09-20 16:26:31 +00:00
|
|
|
.B %d/%m/%y
|
2007-07-09 21:02:59 +00:00
|
|
|
is rather common.
|
2007-04-12 22:42:49 +00:00
|
|
|
This means that in international context this format is
|
2004-11-03 13:51:07 +00:00
|
|
|
ambiguous and should not be used.) (SU)
|
|
|
|
.TP
|
|
|
|
.B %e
|
2007-07-09 21:02:59 +00:00
|
|
|
Like
|
|
|
|
.BR %d ,
|
|
|
|
the day of the month as a decimal number, but a leading
|
2004-11-03 13:51:07 +00:00
|
|
|
zero is replaced by a space. (SU)
|
|
|
|
.TP
|
|
|
|
.B %E
|
|
|
|
Modifier: use alternative format, see below. (SU)
|
|
|
|
.TP
|
|
|
|
.B %F
|
2007-07-09 21:02:59 +00:00
|
|
|
Equivalent to
|
|
|
|
.B %Y-%m-%d
|
2009-02-24 03:05:49 +00:00
|
|
|
(the ISO\ 8601 date format). (C99)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %G
|
2009-02-24 03:05:49 +00:00
|
|
|
The ISO\ 8601 week-based year (see NOTES) with century as a decimal number.
|
2007-07-09 21:02:59 +00:00
|
|
|
The 4-digit year corresponding to the ISO week number (see
|
|
|
|
.BR %V ).
|
|
|
|
This has the same format and value as
|
2009-02-24 00:58:34 +00:00
|
|
|
.BR %Y ,
|
2009-02-24 03:05:49 +00:00
|
|
|
except that if the ISO week number belongs to the previous or next year,
|
2004-11-03 13:51:07 +00:00
|
|
|
that year is used instead. (TZ)
|
|
|
|
.TP
|
|
|
|
.B %g
|
2007-07-09 21:02:59 +00:00
|
|
|
Like
|
|
|
|
.BR %G ,
|
|
|
|
but without century, that is, with a 2-digit year (00-99). (TZ)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %h
|
2007-07-09 21:02:59 +00:00
|
|
|
Equivalent to
|
|
|
|
.BR %b .
|
|
|
|
(SU)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %H
|
|
|
|
The hour as a decimal number using a 24-hour clock (range 00 to 23).
|
|
|
|
.TP
|
|
|
|
.B %I
|
|
|
|
The hour as a decimal number using a 12-hour clock (range 01 to 12).
|
|
|
|
.TP
|
|
|
|
.B %j
|
|
|
|
The day of the year as a decimal number (range 001 to 366).
|
|
|
|
.TP
|
|
|
|
.B %k
|
|
|
|
The hour (24-hour clock) as a decimal number (range 0 to 23);
|
2008-06-28 04:57:20 +00:00
|
|
|
single digits are preceded by a blank.
|
|
|
|
(See also
|
2007-07-09 21:02:59 +00:00
|
|
|
.BR %H .)
|
|
|
|
(TZ)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %l
|
|
|
|
The hour (12-hour clock) as a decimal number (range 1 to 12);
|
2008-06-28 04:57:20 +00:00
|
|
|
single digits are preceded by a blank.
|
|
|
|
(See also
|
2007-07-09 21:02:59 +00:00
|
|
|
.BR %I .)
|
|
|
|
(TZ)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %m
|
|
|
|
The month as a decimal number (range 01 to 12).
|
|
|
|
.TP
|
|
|
|
.B %M
|
|
|
|
The minute as a decimal number (range 00 to 59).
|
|
|
|
.TP
|
|
|
|
.B %n
|
|
|
|
A newline character. (SU)
|
|
|
|
.TP
|
|
|
|
.B %O
|
|
|
|
Modifier: use alternative format, see below. (SU)
|
|
|
|
.TP
|
|
|
|
.B %p
|
2008-06-05 17:52:37 +00:00
|
|
|
Either "AM" or "PM" according to the given time value, or the
|
2004-11-03 13:51:07 +00:00
|
|
|
corresponding strings for the current locale.
|
2008-09-29 11:24:36 +00:00
|
|
|
Noon is treated as "PM" and midnight as "AM".
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %P
|
2007-07-09 21:02:59 +00:00
|
|
|
Like
|
|
|
|
.B %p
|
2008-06-05 17:52:37 +00:00
|
|
|
but in lowercase: "am" or "pm" or a corresponding
|
2004-11-03 13:51:07 +00:00
|
|
|
string for the current locale. (GNU)
|
|
|
|
.TP
|
|
|
|
.B %r
|
|
|
|
The time in a.m. or p.m. notation.
|
2007-07-09 21:02:59 +00:00
|
|
|
In the POSIX locale this is equivalent to
|
2007-12-23 13:08:47 +00:00
|
|
|
.BR "%I:%M:%S %p" .
|
2007-07-09 21:02:59 +00:00
|
|
|
(SU)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %R
|
2007-07-09 21:02:59 +00:00
|
|
|
The time in 24-hour notation (\fB%H:%M\fP). (SU)
|
|
|
|
For a version including the seconds, see
|
|
|
|
.B %T
|
|
|
|
below.
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %s
|
stime.2, time.2, utimensat.2, ctime.3, difftime.3, ftime.3, getspnam.3, mq_receive.3, mq_send.3, rtime.3, sem_wait.3, strftime.3, strptime.3, timeradd.3, rtc.4, core.5, proc.5, icmp.7, time.7: Global fix: Consistently define the Epoch
All definitions of the Epoch have been refactored to the following:
1970-01-01 00:00:00 +0000 (UTC)
That form is more consistent, logical, precise, and internationally
recognizable than the other variants.
Also, some wording has been altered as well.
Signed-off-by: Michael Witten <mfwitten@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-17 03:53:52 +00:00
|
|
|
The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). (TZ)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %S
|
2004-12-20 11:22:11 +00:00
|
|
|
The second as a decimal number (range 00 to 60).
|
|
|
|
(The range is up to 60 to allow for occasional leap seconds.)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %t
|
|
|
|
A tab character. (SU)
|
|
|
|
.TP
|
|
|
|
.B %T
|
2007-07-09 21:02:59 +00:00
|
|
|
The time in 24-hour notation (\fB%H:%M:%S\fP). (SU)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %u
|
|
|
|
The day of the week as a decimal, range 1 to 7, Monday being 1.
|
2007-07-09 21:02:59 +00:00
|
|
|
See also
|
|
|
|
.BR %w .
|
|
|
|
(SU)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %U
|
|
|
|
The week number of the current year as a decimal number,
|
|
|
|
range 00 to 53, starting with the first Sunday as the first day
|
2007-04-12 22:42:49 +00:00
|
|
|
of week 01.
|
2007-07-09 21:02:59 +00:00
|
|
|
See also
|
|
|
|
.B %V
|
|
|
|
and
|
|
|
|
.BR %W .
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %V
|
2009-02-24 03:05:49 +00:00
|
|
|
The ISO\ 8601 week number (see NOTES) of the current year as a decimal number,
|
2004-11-03 13:51:07 +00:00
|
|
|
range 01 to 53, where week 1 is the first week that has at least
|
2009-02-24 03:05:49 +00:00
|
|
|
4 days in the new year.
|
2007-07-09 21:02:59 +00:00
|
|
|
See also
|
|
|
|
.B %U
|
|
|
|
and
|
|
|
|
.BR %W .
|
|
|
|
(SU)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %w
|
|
|
|
The day of the week as a decimal, range 0 to 6, Sunday being 0.
|
2007-07-09 21:02:59 +00:00
|
|
|
See also
|
|
|
|
.BR %u .
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %W
|
|
|
|
The week number of the current year as a decimal number,
|
|
|
|
range 00 to 53, starting with the first Monday as the first day of week 01.
|
|
|
|
.TP
|
|
|
|
.B %x
|
|
|
|
The preferred date representation for the current locale without the time.
|
|
|
|
.TP
|
|
|
|
.B %X
|
|
|
|
The preferred time representation for the current locale without the date.
|
|
|
|
.TP
|
|
|
|
.B %y
|
|
|
|
The year as a decimal number without a century (range 00 to 99).
|
|
|
|
.TP
|
|
|
|
.B %Y
|
|
|
|
The year as a decimal number including the century.
|
|
|
|
.TP
|
|
|
|
.B %z
|
2010-01-16 18:23:49 +00:00
|
|
|
The
|
|
|
|
.I +hhmm
|
|
|
|
or
|
|
|
|
.I -hhmm
|
2010-01-17 04:28:13 +00:00
|
|
|
numeric timezone (that is, the hour and minute offset from UTC). (SU)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %Z
|
2008-09-07 04:17:25 +00:00
|
|
|
The timezone or name or abbreviation.
|
2005-11-22 17:57:48 +00:00
|
|
|
.TP
|
|
|
|
.B %+
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" Nov 05 -- Not in Linux/glibc, but is in some BSDs (according to
|
2005-12-01 09:10:11 +00:00
|
|
|
.\" their man pages)
|
2007-04-12 22:42:49 +00:00
|
|
|
The date and time in
|
|
|
|
.BR date (1)
|
2005-11-22 17:57:48 +00:00
|
|
|
format. (TZ)
|
|
|
|
(Not supported in glibc2.)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B %%
|
2008-06-09 15:49:35 +00:00
|
|
|
A literal \(aq%\(aq character.
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2007-04-12 22:42:49 +00:00
|
|
|
Some conversion specifications can be modified by preceding the
|
2007-12-23 13:08:47 +00:00
|
|
|
conversion specifier character by the
|
|
|
|
.B E
|
|
|
|
or
|
|
|
|
.B O
|
2007-04-12 22:42:49 +00:00
|
|
|
.I modifier
|
2005-11-23 09:01:15 +00:00
|
|
|
to indicate that an alternative format should be used.
|
2004-11-03 13:51:07 +00:00
|
|
|
If the alternative format or specification does not exist for
|
2007-06-08 09:56:56 +00:00
|
|
|
the current locale, the behavior will be as if the unmodified
|
2004-11-03 13:51:07 +00:00
|
|
|
conversion specification were used. (SU)
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
The Single UNIX Specification mentions
|
2007-12-23 13:02:05 +00:00
|
|
|
.BR %Ec ,
|
|
|
|
.BR %EC ,
|
|
|
|
.BR %Ex ,
|
|
|
|
.BR %EX ,
|
|
|
|
.BR %Ey ,
|
|
|
|
.BR %EY ,
|
|
|
|
.BR %Od ,
|
|
|
|
.BR %Oe ,
|
|
|
|
.BR %OH ,
|
|
|
|
.BR %OI ,
|
|
|
|
.BR %Om ,
|
|
|
|
.BR %OM ,
|
|
|
|
.BR %OS ,
|
|
|
|
.BR %Ou ,
|
|
|
|
.BR %OU ,
|
|
|
|
.BR %OV ,
|
|
|
|
.BR %Ow ,
|
|
|
|
.BR %OW ,
|
|
|
|
.BR %Oy ,
|
2007-12-23 13:08:47 +00:00
|
|
|
where the effect of the
|
|
|
|
.B O
|
|
|
|
modifier is to use
|
2004-11-03 13:51:07 +00:00
|
|
|
alternative numeric symbols (say, roman numerals), and that of the
|
|
|
|
E modifier is to use a locale-dependent alternative representation.
|
|
|
|
.PP
|
|
|
|
The broken-down time structure \fItm\fP is defined in \fI<time.h>\fP.
|
|
|
|
See also
|
|
|
|
.BR ctime (3).
|
|
|
|
.SH "RETURN VALUE"
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR strftime ()
|
|
|
|
function returns the number of characters placed
|
2006-01-13 02:09:44 +00:00
|
|
|
in the array \fIs\fP, not including the terminating null byte,
|
|
|
|
provided the string, including the terminating null byte, fits.
|
2004-11-03 13:51:07 +00:00
|
|
|
Otherwise, it returns 0, and the contents of the array is undefined.
|
2007-06-12 04:17:57 +00:00
|
|
|
(This behavior applies since at least libc 4.4.4;
|
|
|
|
very old versions of libc, such as libc 4.4.1,
|
|
|
|
would return \fImax\fP if the array was too small.)
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
|
|
|
Note that the return value 0 does not necessarily indicate an error;
|
2007-07-09 21:02:59 +00:00
|
|
|
for example, in many locales
|
|
|
|
.B %p
|
|
|
|
yields an empty string.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH ENVIRONMENT
|
2007-12-16 13:39:24 +00:00
|
|
|
The environment variables
|
|
|
|
.B TZ
|
|
|
|
and
|
2007-06-22 20:40:07 +00:00
|
|
|
.B LC_TIME
|
|
|
|
are used.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "CONFORMING TO"
|
2006-08-03 13:57:30 +00:00
|
|
|
SVr4, C89, C99.
|
2004-11-03 13:51:07 +00:00
|
|
|
There are strict inclusions between the set of conversions
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
given in ANSI C (unmarked), those given in the Single UNIX Specification
|
2004-11-03 13:51:07 +00:00
|
|
|
(marked SU), those given in Olson's timezone package (marked TZ),
|
2007-07-09 21:02:59 +00:00
|
|
|
and those given in glibc (marked GNU), except that
|
|
|
|
.B %+
|
|
|
|
is not supported in glibc2.
|
2007-04-12 22:42:49 +00:00
|
|
|
On the other hand glibc2 has several more extensions.
|
2004-11-03 13:51:07 +00:00
|
|
|
POSIX.1 only refers to ANSI C; POSIX.2 describes under
|
|
|
|
.BR date (1)
|
|
|
|
several extensions that could apply to
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR strftime ()
|
2004-11-03 13:51:07 +00:00
|
|
|
as well.
|
2007-07-09 21:02:59 +00:00
|
|
|
The
|
|
|
|
.B %F
|
|
|
|
conversion is in C99 and POSIX.1-2001.
|
2005-03-31 13:22:34 +00:00
|
|
|
|
2007-07-09 21:02:59 +00:00
|
|
|
In SUSv2, the
|
|
|
|
.B %S
|
|
|
|
specifier allowed a range of 00 to 61,
|
2005-03-31 13:22:34 +00:00
|
|
|
to allow for the theoretical possibility of a minute that
|
|
|
|
included a double leap second
|
|
|
|
(there never has been such a minute).
|
2007-05-18 10:30:02 +00:00
|
|
|
.SH NOTES
|
2009-02-24 03:05:49 +00:00
|
|
|
.SS ISO 8601 Week Dates
|
|
|
|
.BR %G ,
|
|
|
|
.BR %g ,
|
|
|
|
and
|
|
|
|
.BR %V
|
|
|
|
yield values calculated from the week-based year defined by the
|
|
|
|
ISO\ 8601 standard.
|
|
|
|
In this system, weeks start on a Monday, and are numbered from 01,
|
|
|
|
for the first week, up to 52 or 53, for the last week.
|
|
|
|
Week 1 is the first week where four or more days fall within the
|
|
|
|
new year (or, synonymously, week 01 is:
|
|
|
|
the first week of the year that contains a Thursday;
|
|
|
|
or, the week that has 4 January in it).
|
|
|
|
When three of fewer days of the first calendar week of the new year fall
|
|
|
|
within that year,
|
|
|
|
then the ISO 8601 week-based system counts those days as part of week 53
|
|
|
|
of the preceding year.
|
|
|
|
For example, 1 January 2010 is a Friday,
|
|
|
|
meaning that just three days of that calendar week fall in 2010.
|
|
|
|
Thus, the ISO\ 8601 week-based system considers these days to be part of
|
|
|
|
week 53 (\fB%V\fP) of the year 2009 (\fB%G\fP) ;
|
2009-09-28 09:11:11 +00:00
|
|
|
week 01 of ISO\ 8601 year 2010 starts on Monday, 4 January 2010.
|
2007-05-18 10:30:02 +00:00
|
|
|
.SS Glibc Notes
|
2005-11-23 09:01:15 +00:00
|
|
|
Glibc provides some extensions for conversion specifications.
|
|
|
|
(These extensions are not specified in POSIX.1-2001, but a few other
|
|
|
|
systems provide similar features.)
|
|
|
|
.\" HP-UX and Tru64 also have features like this.
|
2008-06-09 15:49:35 +00:00
|
|
|
Between the \(aq%\(aq character and the conversion specifier character,
|
2007-04-12 22:42:49 +00:00
|
|
|
an optional
|
|
|
|
.I flag
|
2005-11-23 09:01:15 +00:00
|
|
|
and field
|
2007-04-12 22:42:49 +00:00
|
|
|
.I width
|
|
|
|
may be specified.
|
2007-12-23 13:08:47 +00:00
|
|
|
(These precede the
|
|
|
|
.B E
|
|
|
|
or
|
|
|
|
.B O
|
|
|
|
modifiers, if present.)
|
2005-11-23 09:01:15 +00:00
|
|
|
|
2005-11-22 18:41:24 +00:00
|
|
|
The following flag characters are permitted:
|
|
|
|
.TP
|
|
|
|
.B _
|
|
|
|
(underscore)
|
2005-11-23 09:01:15 +00:00
|
|
|
Pad a numeric result string with spaces.
|
2005-11-22 18:41:24 +00:00
|
|
|
.TP
|
2007-04-12 22:42:49 +00:00
|
|
|
.B \-
|
2005-11-22 18:41:24 +00:00
|
|
|
(dash)
|
2005-11-23 09:01:15 +00:00
|
|
|
Do not pad a numeric result string.
|
2005-11-22 18:41:24 +00:00
|
|
|
.TP
|
|
|
|
.B 0
|
2007-04-12 22:42:49 +00:00
|
|
|
Pad a numeric result string with zeros even if the conversion
|
2005-11-23 09:01:15 +00:00
|
|
|
specifier character uses space-padding by default.
|
2005-11-22 18:41:24 +00:00
|
|
|
.TP
|
|
|
|
.B ^
|
2005-11-23 09:01:15 +00:00
|
|
|
Convert alphabetic characters in result string to upper case.
|
2005-11-22 18:41:24 +00:00
|
|
|
.TP
|
|
|
|
.B #
|
2007-04-12 22:42:49 +00:00
|
|
|
Swap the case of the result string.
|
|
|
|
(This flag only works with certain conversion specifier characters,
|
2007-07-09 21:02:59 +00:00
|
|
|
and of these, it is only really useful with
|
2007-12-23 13:03:22 +00:00
|
|
|
.BR %Z .)
|
2005-11-22 18:41:24 +00:00
|
|
|
.PP
|
|
|
|
An optional decimal width specifier may follow the (possibly absent) flag.
|
|
|
|
If the natural size of the field is smaller than this width,
|
2005-11-23 09:01:15 +00:00
|
|
|
then the result string is padded (on the left) to the specified width.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH BUGS
|
2007-07-09 21:02:59 +00:00
|
|
|
Some buggy versions of
|
|
|
|
.BR gcc (1)
|
|
|
|
complain about the use of
|
|
|
|
.BR %c :
|
2004-11-03 13:51:07 +00:00
|
|
|
.IR "warning: `%c' yields only last 2 digits of year in some locales" .
|
2007-07-09 21:02:59 +00:00
|
|
|
Of course programmers are encouraged to use
|
2007-12-10 14:49:55 +00:00
|
|
|
.BR %c ,
|
|
|
|
it gives the preferred date and time representation.
|
2007-04-12 22:42:49 +00:00
|
|
|
One meets all kinds of strange obfuscations
|
2007-07-09 21:02:59 +00:00
|
|
|
to circumvent this
|
|
|
|
.BR gcc (1)
|
|
|
|
problem.
|
2007-04-12 22:42:49 +00:00
|
|
|
A relatively clean one is to add an
|
2004-11-03 13:51:07 +00:00
|
|
|
intermediate function
|
2007-12-19 05:53:30 +00:00
|
|
|
.in +4n
|
2007-04-05 13:29:41 +00:00
|
|
|
.nf
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
size_t
|
|
|
|
my_strftime(char *s, size_t max, const char *fmt,
|
|
|
|
const struct tm *tm)
|
2007-04-05 13:29:41 +00:00
|
|
|
{
|
|
|
|
return strftime(s, max, fmt, tm);
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
2007-04-05 13:29:41 +00:00
|
|
|
.fi
|
2007-12-19 05:53:30 +00:00
|
|
|
.in
|
2007-06-15 05:59:35 +00:00
|
|
|
|
|
|
|
Nowadays,
|
|
|
|
.BR gcc (1)
|
|
|
|
provides the \fI\-Wno\-format\-y2k\fP option to prevent the warning,
|
|
|
|
so that the above workaround is no longer required.
|
2012-03-12 15:08:12 +00:00
|
|
|
.SH EXAMPLE
|
2010-01-17 04:28:13 +00:00
|
|
|
.BR "RFC\ 2822-compliant date format"
|
|
|
|
(with an English locale for %a and %b)
|
|
|
|
.PP
|
|
|
|
.in +2n
|
|
|
|
"%a,\ %d\ %b\ %Y\ %T\ %z"
|
|
|
|
.PP
|
|
|
|
.BR "RFC\ 822-compliant date format"
|
|
|
|
(with an English locale for %a and %b)
|
|
|
|
.PP
|
|
|
|
.in +2n
|
|
|
|
"%a,\ %d\ %b\ %y\ %T\ %z"
|
|
|
|
.SS Example Program
|
2007-04-12 22:42:49 +00:00
|
|
|
The program below can be used to experiment with
|
2005-11-23 09:34:07 +00:00
|
|
|
.BR strftime ().
|
2008-10-28 16:01:42 +00:00
|
|
|
.PP
|
|
|
|
Some examples of the result string produced by the glibc implementation of
|
|
|
|
.BR strftime ()
|
|
|
|
are as follows:
|
|
|
|
.in +4n
|
2005-11-23 09:34:07 +00:00
|
|
|
.nf
|
|
|
|
|
2008-10-28 16:01:42 +00:00
|
|
|
.RB "$" " ./a.out \(aq%m\(aq"
|
|
|
|
Result string is "11"
|
|
|
|
.RB "$" " ./a.out \(aq%5m\(aq"
|
|
|
|
Result string is "00011"
|
|
|
|
.RB "$" " ./a.out \(aq%_5m\(aq"
|
|
|
|
Result string is " 11"
|
|
|
|
.fi
|
|
|
|
.in
|
2010-01-17 04:28:13 +00:00
|
|
|
.PP
|
|
|
|
Here's the program source:
|
2008-10-28 16:01:42 +00:00
|
|
|
.nf
|
2010-01-17 04:28:13 +00:00
|
|
|
|
2005-11-23 09:34:07 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char outstr[200];
|
|
|
|
time_t t;
|
|
|
|
struct tm *tmp;
|
|
|
|
|
|
|
|
t = time(NULL);
|
|
|
|
tmp = localtime(&t);
|
|
|
|
if (tmp == NULL) {
|
|
|
|
perror("localtime");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) {
|
|
|
|
fprintf(stderr, "strftime returned 0");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Result string is \\"%s\\"\\n", outstr);
|
|
|
|
exit(EXIT_SUCCESS);
|
2010-01-17 04:28:13 +00:00
|
|
|
}
|
2005-11-23 09:34:07 +00:00
|
|
|
.fi
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR date (1),
|
|
|
|
.BR time (2),
|
|
|
|
.BR ctime (3),
|
|
|
|
.BR setlocale (3),
|
|
|
|
.BR sprintf (3),
|
|
|
|
.BR strptime (3)
|