xref: /csrg-svn/lib/libc/string/strftime.3 (revision 61193)
1*61193Sbostic.\" Copyright (c) 1989, 1991, 1993
2*61193Sbostic.\"	The Regents of the University of California.  All rights reserved.
337122Sbostic.\"
450324Sbostic.\" This code is derived from software contributed to Berkeley by
550324Sbostic.\" the American National Standards Committee X3, on Information
650324Sbostic.\" Processing Systems.
750324Sbostic.\"
843567Strent.\" %sccs.include.redist.man%
937122Sbostic.\"
10*61193Sbostic.\"     @(#)strftime.3	8.1 (Berkeley) 06/04/93
1137122Sbostic.\"
1248351Scael.Dd
1348351Scael.Dt STRFTIME 3
1448351Scael.Os
1548351Scael.Sh NAME
1648351Scael.Nm strftime
1748351Scael.Nd format date and time
1848351Scael.Sh SYNOPSIS
1948351Scael.Fd #include <sys/types.h>
2048351Scael.Fd #include <time.h>
2148351Scael.Fd #include <string.h>
2248351Scael.Ft size_t
2348351Scael.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
2448351Scael.Sh DESCRIPTION
2537122SbosticThe
2648351Scael.Fn strftime
2737122Sbosticfunction formats the information from
2848351Scael.Fa timeptr
2937122Sbosticinto the buffer
3048351Scael.Fa buf
3137122Sbosticaccording to the string pointed to by
3248351Scael.Fa format .
3348351Scael.Pp
3437122SbosticThe
3548351Scael.Fa format
3637122Sbosticstring consists of zero or more conversion specifications and
3737122Sbosticordinary characters.
3837122SbosticAll ordinary characters are copied directly into the buffer.
3948351ScaelA conversion specification consists of a percent sign
4048351Scael.Dq Ql %
4137122Sbosticand one other character.
4248351Scael.Pp
4337122SbosticNo more than
4448351Scael.Fa maxsize
4537122Sbosticcharacters will be placed into the array.
4637122SbosticIf the total number of resulting characters, including the terminating
4737122Sbosticnull character, is not more than
4848351Scael.Fa maxsize ,
4948351Scael.Fn strftime
5037122Sbosticreturns the number of characters in the array, not counting the
5137122Sbosticterminating null.
5237122SbosticOtherwise, zero is returned.
5348351Scael.Pp
5437122SbosticEach conversion specification is replaced by the characters as
5537122Sbosticfollows which are then copied into the buffer.
5648351Scael.Bl -tag -width "xxxx"
5748351Scael.It Cm \&%A
5837122Sbosticis replaced by the full weekday name.
5948351Scael.It Cm %a
6037122Sbosticis replaced by the abbreviated weekday name, where the abbreviation
6137122Sbosticis the first three characters.
6248351Scael.It Cm \&%B
6337122Sbosticis replaced by the full month name.
6448351Scael.It Cm %b  or  %h
6537122Sbosticis replaced by the abbreviated month name, where the abbreviation is
6637122Sbosticthe first three characters.
6748351Scael.It Cm \&%C
6848351Scaelis equivalent to
6948351Scael.Dq Li %a %b %e %H:%M:%S %Y
7048351Scael(the format produced by
7148351Scael.Xr asctime 3 .
7248351Scael.It Cm %c
7348351Scaelis equivalent to
7448351Scael.Dq Li %m/%d/%y .
7548351Scael.It Cm \&%D
7648351Scaelis replaced by the date in the format
7748351Scael.Dq Ql mm/dd/yy .
7848351Scael.It Cm %d
7937122Sbosticis replaced by the day of the month as a decimal number (01-31).
8048351Scael.It Cm %e
8137346Sbosticis replaced by the day of month as a decimal number (1-31); single
8237346Sbosticdigits are preceded by a blank.
8348351Scael.It Cm \&%H
8437122Sbosticis replaced by the hour (24-hour clock) as a decimal number (00-23).
8548351Scael.It Cm \&%I
8637122Sbosticis replaced by the hour (12-hour clock) as a decimal number (01-12).
8748351Scael.It Cm %j
8837122Sbosticis replaced by the day of the year as a decimal number (001-366).
8948351Scael.It Cm %k
9037346Sbosticis replaced by the hour (24-hour clock) as a decimal number (0-23);
9137346Sbosticsingle digits are preceded by a blank.
9248351Scael.It Cm %l
9346041Sbosticis replaced by the hour (12-hour clock) as a decimal number (1-12);
9437346Sbosticsingle digits are preceded by a blank.
9548351Scael.It Cm \&%M
9637138Sbosticis replaced by the minute as a decimal number (00-59).
9748351Scael.It Cm %m
9837122Sbosticis replaced by the month as a decimal number (01-12).
9948351Scael.It Cm %n
10037138Sbosticis replaced by a newline.
10148351Scael.It Cm %p
10248351Scaelis replaced by either
10348351Scael.Dq Tn AM
10448351Scaelor
10548351Scael.Dq Tn PM
10648351Scaelas appropriate.
10748351Scael.It Cm \&%R
10848351Scaelis equivalent to
10948351Scael.Dq Li %H:%M
11048351Scael.It Cm %r
11148351Scaelis equivalent to
11248351Scael.Dq Li %I:%M:%S %p .
11348351Scael.It Cm %t
11437138Sbosticis replaced by a tab.
11548351Scael.It Cm \&%S
11637122Sbosticis replaced by the second as a decimal number (00-60).
11748351Scael.It Cm %s
11845668Sbosticis replaced by the number of seconds since the Epoch, UCT (see
11948351Scael.Xr mktime 3 ) .
12048351Scael.It Cm \&%T No or Cm \&%X
12148351Scaelis equivalent to
12248351Scael.Dq Li %H:%M:%S .
12348351Scael.It Cm \&%U
12437122Sbosticis replaced by the week number of the year (Sunday as the first day of
12537122Sbosticthe week) as a decimal number (00-53).
12648351Scael.It Cm \&%W
12737122Sbosticis replaced by the week number of the year (Monday as the first day of
12837122Sbosticthe week) as a decimal number (00-53).
12948351Scael.It Cm %w
13037122Sbosticis replaced by the weekday (Sunday as the first day of the week)
13137122Sbosticas a decimal number (0-6).
13248351Scael.It Cm %x
13348351Scaelis equivalent to
13448351Scael.Dq Li %m/%d/%y %H:%M:%S .
13548351Scael.It Cm \&%Y
13637122Sbosticis replaced by the year with century as a decimal number.
13748351Scael.It Cm %y
13837122Sbosticis replaced by the year without century as a decimal number (00-99).
13948351Scael.It Cm \&%Z
14037122Sbosticis replaced by the time zone name.
14148351Scael.It Cm %%
14248351Scaelis replaced by
14348351Scael.Ql % .
14448351Scael.El
14548351Scael.Sh SEE ALSO
14648351Scael.Xr date 1 ,
14748351Scael.Xr ctime 3 ,
14848351Scael.Xr printf 1 ,
14948351Scael.Xr printf 3
15048351Scael.Sh STANDARDS
15148351ScaelThe
15248351Scael.Fn strftime
15348351Scaelfunction
15448351Scaelconforms to
15548351Scael.St -ansiC .
15648351ScaelThe
15748351Scael.Ql %s
15848351Scaelconversion specification is an extension.
15948351Scael.Sh BUGS
16045695SbosticThere is no conversion specification for the phase of the moon.
161