.\" 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 .\" .\" 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. .\" .\" 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 .\" 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 .TH STRFTIME 3 "July 2, 1993" "GNU" "Linux Programmer's Manual" .SH NAME strftime \- format date and time .SH SYNOPSIS .nf .B #include .sp .BI "size_t strftime(char *" s ", size_t " max ", const char *" format , .BI " const struct tm *" tm ); .fi .SH DESCRIPTION The \fBstrftime()\fP function formats the broken-down time \fItm\fP according to the format specification \fIformat\fP and places the result in the character array \fIs\fP of size \fImax\fP. .PP Ordinary characters placed in the format string are copied to \fIs\fP without conversion. Conversion specifiers are introduced by a `%' character, and are replaced in \fIs\fP as follows: .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 %d The day of the month as a decimal number (range 01 to 31). .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 %m The month as a decimal number (range 01 to 12). .TP .B %M The minute as a decimal number. .TP .B %p Either `am' or `pm' according to the given time value, or the corresponding strings for the current locale. .TP .B %S The second as a decimal number. .TP .B %U The week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week. .TP .B %W The week number of the current year as a decimal number, starting with the first Monday as the first day of the first week. .TP .B %w The day of the week as a decimal, Sunday being 0. .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 The time zone or name or abbreviation. .TP .B %% A literal `%' character. .PP The broken-down time structure \fItm\fP is defined in \fI\fP as follows: .sp .RS .nf .ne 12 .ta 8n 16n 32n struct tm { int tm_sec; /* seconds */ int tm_min; /* minutes */ int tm_hour; /* hours */ int tm_mday; /* day of the month */ int tm_mon; /* month */ int tm_year; /* year */ int tm_wday; /* day of the week */ int tm_yday; /* day in the year */ int tm_isdst; /* daylight saving time */ }; .ta .fi .RE .PP The members of the \fItm\fP structure are: .TP .I tm_sec The number of seconds after the minute, normally in the range 0 to 59, but can be up to 61 to allow for leap seconds. .TP .I tm_min The number of minutes after the hour, in the range 0 to 59. .TP .I tm_hour The number of hours past midnight, in the range 0 to 23. .TP .I tm_mday The day of the month, in the range 1 to 31. .TP .I tm_mon The number of months since January, in the range 0 to 11. .TP .I tm_year The number of years since 1900. .TP .I tm_wday The number of days since Sunday, in the range 0 to 6. .TP .I tm_yday The number of days since January 1, in the range 0 to 365. .TP .I tm_isdst A flag that indicates whether daylight saving time is in effect at the time described. The value is positive if daylight saving time is in effect, zero if it is not, and negative if the information is not available. .SH "RETURN VALUE" The \fBstrftime()\fP function returns the number of characters placed in the array \fIs\fP, not including the terminating NULL character, provided the string, including the terminating NULL, fits. Otherwise, it returns 0, and the contents of the array is undefined. (Thus at least since 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.) .LP Note that the return value 0 does not necessarily indicate an error; for example, in many locales %p yields an empty string. .SH "CONFORMING TO" ANSI C, SVID 3, POSIX, BSD 4.3, ISO 9899 .SH "SEE ALSO" .BR date "(1), " time "(2), " ctime "(3), " setlocale "(3), " sprintf (3)