• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1newstrftime(3)             Library Functions Manual             newstrftime(3)
2
3NAME
4       strftime - format date and time
5
6SYNOPSIS
7       #include <time.h>
8
9       size_t strftime(char *restrict buf, size_t maxsize,
10           char const *restrict format, struct tm const *restrict timeptr);
11
12       cc ... -ltz
13
14DESCRIPTION
15       The strftime function formats the information from *timeptr into the
16       array pointed to by buf according to the string pointed to by format.
17
18       The format string consists of zero or more conversion specifications
19       and ordinary characters.  All ordinary characters are copied directly
20       into the array.  A conversion specification consists of a percent sign
21       and one other character.
22
23       No more than maxsize bytes are placed into the array.
24
25       Each conversion specification is replaced by the characters as follows
26       which are then copied into the array.  The characters depend on the
27       values of zero or more members of *timeptr as specified by brackets in
28       the description.  If a bracketed member name is followed by "+",
29       strftime can use the named member even though POSIX.1-2017 does not
30       list it; if the name is followed by "-", strftime ignores the member
31       even though POSIX.1-2017 lists it which means portable code should set
32       it.  For portability, *timeptr should be initialized as if by a
33       successful call to gmtime, localtime, mktime, timegm, or similar
34       functions.
35
36       %A     is replaced by the locale's full weekday name.  [tm_wday]
37
38       %a     is replaced by the locale's abbreviated weekday name.  [tm_wday]
39
40       %B     is replaced by the locale's full month name.  [tm_mon]
41
42       %b or %h
43              is replaced by the locale's abbreviated month name.  [tm_mon]
44
45       %C     is  replaced by the century (a year divided by 100 and truncated
46              to an integer) as a decimal number, with at least two digits  by
47              default.  [tm_year]
48
49       %c     is   replaced   by   the  locale's  appropriate  date  and  time
50              representation.  [tm_year, tm_yday,  tm_mon,  tm_mday,  tm_wday,
51              tm_hour, tm_min, tm_sec, tm_gmtoff+, tm_zone+, tm_isdst-].
52
53       %D     is equivalent to %m/%d/%y.  [tm_year, tm_mon, tm_mday]
54
55       %d     is replaced by the day of the month as a decimal number [01,31].
56              [tm_mday]
57
58       %e     is  replaced  by  the  day  of month as a decimal number [1,31];
59              single digits are preceded by a blank.  [tm_mday]
60
61       %F     is equivalent to %Y-%m-%d (the ISO 8601 date format).  [tm_year,
62              tm_mon, tm_mday]
63
64       %G     is replaced by the ISO 8601  year  with  century  as  a  decimal
65              number.   See  also  the %V conversion specification.  [tm_year,
66              tm_yday, tm_wday]
67
68       %g     is replaced by the ISO 8601 year without century  as  a  decimal
69              number [00,99].  This is the year that includes the greater part
70              of the week.  (Monday as the first day of a week).  See also the
71              %V conversion specification.  [tm_year, tm_yday, tm_wday]
72
73       %H     is  replaced  by  the  hour  (24-hour clock) as a decimal number
74              [00,23].  [tm_hour]
75
76       %I     is replaced by the hour (12-hour  clock)  as  a  decimal  number
77              [01,12].  [tm_hour]
78
79       %j     is  replaced  by  the  day  of  the  year  as  a  decimal number
80              [001,366].  [tm_yday]
81
82       %k     is replaced by the hour (24-hour  clock)  as  a  decimal  number
83              [0,23]; single digits are preceded by a blank.  [tm_hour]
84
85       %l     is  replaced  by  the  hour  (12-hour clock) as a decimal number
86              [1,12]; single digits are preceded by a blank.  [tm_hour]
87
88       %M     is replaced by the minute as a decimal number [00,59].  [tm_min]
89
90       %m     is replaced by the month as a decimal number [01,12].  [tm_mon]
91
92       %n     is replaced by a newline.
93
94       %p     is replaced by the locale's equivalent of either "AM"  or  "PM".
95              [tm_hour]
96
97       %R     is replaced by the time in the format %H:%M.  [tm_hour, tm_min]
98
99       %r     is replaced by the locale's representation of 12-hour clock time
100              using AM/PM notation.  [tm_hour, tm_min, tm_sec]
101
102       %S     is  replaced  by  the  second  as a decimal number [00,60].  The
103              range of seconds is [00,60] instead of [00,59] to allow for  the
104              periodic occurrence of leap seconds.  [tm_sec]
105
106       %s     is  replaced  by  the  number  of  seconds  since the Epoch (see
107              ctime(3)).  Although %s is reliable in this  implementation,  it
108              can  have glitches on other platforms (notably platforms lacking
109              tm_gmtoff), so  portable  code  should  format  a  time_t  value
110              directly  via  something  like  sprintf instead of via localtime
111              followed by strftime  with  "%s".   [tm_year,  tm_mon,  tm_mday,
112              tm_hour, tm_min, tm_sec, tm_gmtoff+, tm_isdst-].
113
114       %T     is  replaced  by  the  time  in  the format %H:%M:%S.  [tm_hour,
115              tm_min, tm_sec]
116
117       %t     is replaced by a tab.
118
119       %U     is replaced by the week number of the year (Sunday as the  first
120              day  of  the  week)  as  a  decimal  number  [00,53].  [tm_wday,
121              tm_yday, tm_year-]
122
123       %u     is replaced by the weekday (Monday as the first day of the week)
124              as a decimal number [1,7].  [tm_wday]
125
126       %V     is replaced by the week number of the year (Monday as the  first
127              day  of  the  week)  as  a  decimal number [01,53].  If the week
128              containing January 1 has four or more days in the new year, then
129              it is week 1; otherwise it is week 53 of the previous year,  and
130              the next week is week 1.  The year is given by the %G conversion
131              specification.  [tm_year, tm_yday, tm_wday]
132
133       %W     is  replaced by the week number of the year (Monday as the first
134              day of  the  week)  as  a  decimal  number  [00,53].   [tm_yday,
135              tm_wday]
136
137       %w     is replaced by the weekday (Sunday as the first day of the week)
138              as a decimal number [0,6].  [tm_year, tm_yday, tm_wday]
139
140       %X     is  replaced  by  the  locale's appropriate time representation.
141              [tm_year-,  tm_yday-,  tm_mon-,  tm_mday-,  tm_wday-,   tm_hour,
142              tm_min, tm_sec, tm_gmtoff+, tm_zone+, tm_isdst-].
143
144       %x     is  replaced  by  the  locale's appropriate date representation.
145              [tm_year, tm_yday, tm_mon, tm_mday, tm_wday, tm_hour-,  tm_min-,
146              tm_sec-, tm_gmtoff-, tm_zone-, tm_isdst-].
147
148       %Y     is  replaced  by  the  year  with  century  as a decimal number.
149              [tm_year]
150
151       %y     is replaced by the year without  century  as  a  decimal  number
152              [00,99].  [tm_year]
153
154       %Z     is  replaced  by  the  time  zone  abbreviation, or by the empty
155              string if this is not determinable.  [tm_zone+, tm_isdst-]
156
157       %z     is replaced by the offset from the Prime Meridian in the  format
158              +HHMM  or  -HHMM (ISO 8601) as appropriate, with positive values
159              representing locations east of Greenwich, or by the empty string
160              if this is not determinable.  The numeric time zone abbreviation
161              -0000 is used when the time is Universal Time but local time  is
162              indeterminate;  by  convention  this is used for locations while
163              uninhabited, and corresponds to a zero offset when the time zone
164              abbreviation begins with "-".  [tm_gmtoff+, tm_zone+, tm_isdst-]
165
166       %%     is replaced by a single %.
167
168       %+     is replaced by the locale's date and  time  in  date(1)  format.
169              [tm_year,  tm_yday,  tm_mon,  tm_mday, tm_wday, tm_hour, tm_min,
170              tm_sec, tm_gmtoff, tm_zone]
171
172       As a side effect, strftime also behaves as if tzset were called.   This
173       is  for compatibility with older platforms, as required by POSIX; it is
174       not needed for tzset's own use.
175
176RETURN VALUE
177       If the conversion is successful, strftime returns the number  of  bytes
178       placed  into  the  array,  not  counting  the terminating NUL; errno is
179       unchanged if the returned value is zero.  Otherwise, errno  is  set  to
180       indicate  the  error,  zero  is  returned,  and  the array contents are
181       unspecified.
182
183ERRORS
184       This function fails if:
185
186       [ERANGE]
187              The total number of resulting bytes, including  the  terminating
188              NUL character, is more than maxsize.
189
190       This function may fail if:
191
192       [EOVERFLOW]
193              The  format  includes an %s conversion and the number of seconds
194              since the Epoch cannot be represented in a time_t.
195
196SEE ALSO
197       date(1), getenv(3), newctime(3), newtzset(3), time(2), tzfile(5)
198
199BUGS
200       There is no conversion specification for the phase of the moon.
201
202Time Zone Database                                              newstrftime(3)
203