14616d0f9Sopenharmony_cinewstrftime(3) Library Functions Manual newstrftime(3) 24616d0f9Sopenharmony_ci 34616d0f9Sopenharmony_ciNAME 44616d0f9Sopenharmony_ci strftime - format date and time 54616d0f9Sopenharmony_ci 64616d0f9Sopenharmony_ciSYNOPSIS 74616d0f9Sopenharmony_ci #include <time.h> 84616d0f9Sopenharmony_ci 94616d0f9Sopenharmony_ci size_t strftime(char *restrict buf, size_t maxsize, 104616d0f9Sopenharmony_ci char const *restrict format, struct tm const *restrict timeptr); 114616d0f9Sopenharmony_ci 124616d0f9Sopenharmony_ci cc ... -ltz 134616d0f9Sopenharmony_ci 144616d0f9Sopenharmony_ciDESCRIPTION 154616d0f9Sopenharmony_ci The strftime function formats the information from *timeptr into the 164616d0f9Sopenharmony_ci array pointed to by buf according to the string pointed to by format. 174616d0f9Sopenharmony_ci 184616d0f9Sopenharmony_ci The format string consists of zero or more conversion specifications 194616d0f9Sopenharmony_ci and ordinary characters. All ordinary characters are copied directly 204616d0f9Sopenharmony_ci into the array. A conversion specification consists of a percent sign 214616d0f9Sopenharmony_ci and one other character. 224616d0f9Sopenharmony_ci 234616d0f9Sopenharmony_ci No more than maxsize bytes are placed into the array. 244616d0f9Sopenharmony_ci 254616d0f9Sopenharmony_ci Each conversion specification is replaced by the characters as follows 264616d0f9Sopenharmony_ci which are then copied into the array. The characters depend on the 274616d0f9Sopenharmony_ci values of zero or more members of *timeptr as specified by brackets in 284616d0f9Sopenharmony_ci the description. If a bracketed member name is followed by "+", 294616d0f9Sopenharmony_ci strftime can use the named member even though POSIX.1-2017 does not 304616d0f9Sopenharmony_ci list it; if the name is followed by "-", strftime ignores the member 314616d0f9Sopenharmony_ci even though POSIX.1-2017 lists it which means portable code should set 324616d0f9Sopenharmony_ci it. For portability, *timeptr should be initialized as if by a 334616d0f9Sopenharmony_ci successful call to gmtime, localtime, mktime, timegm, or similar 344616d0f9Sopenharmony_ci functions. 354616d0f9Sopenharmony_ci 364616d0f9Sopenharmony_ci %A is replaced by the locale's full weekday name. [tm_wday] 374616d0f9Sopenharmony_ci 384616d0f9Sopenharmony_ci %a is replaced by the locale's abbreviated weekday name. [tm_wday] 394616d0f9Sopenharmony_ci 404616d0f9Sopenharmony_ci %B is replaced by the locale's full month name. [tm_mon] 414616d0f9Sopenharmony_ci 424616d0f9Sopenharmony_ci %b or %h 434616d0f9Sopenharmony_ci is replaced by the locale's abbreviated month name. [tm_mon] 444616d0f9Sopenharmony_ci 454616d0f9Sopenharmony_ci %C is replaced by the century (a year divided by 100 and truncated 464616d0f9Sopenharmony_ci to an integer) as a decimal number, with at least two digits by 474616d0f9Sopenharmony_ci default. [tm_year] 484616d0f9Sopenharmony_ci 494616d0f9Sopenharmony_ci %c is replaced by the locale's appropriate date and time 504616d0f9Sopenharmony_ci representation. [tm_year, tm_yday, tm_mon, tm_mday, tm_wday, 514616d0f9Sopenharmony_ci tm_hour, tm_min, tm_sec, tm_gmtoff+, tm_zone+, tm_isdst-]. 524616d0f9Sopenharmony_ci 534616d0f9Sopenharmony_ci %D is equivalent to %m/%d/%y. [tm_year, tm_mon, tm_mday] 544616d0f9Sopenharmony_ci 554616d0f9Sopenharmony_ci %d is replaced by the day of the month as a decimal number [01,31]. 564616d0f9Sopenharmony_ci [tm_mday] 574616d0f9Sopenharmony_ci 584616d0f9Sopenharmony_ci %e is replaced by the day of month as a decimal number [1,31]; 594616d0f9Sopenharmony_ci single digits are preceded by a blank. [tm_mday] 604616d0f9Sopenharmony_ci 614616d0f9Sopenharmony_ci %F is equivalent to %Y-%m-%d (the ISO 8601 date format). [tm_year, 624616d0f9Sopenharmony_ci tm_mon, tm_mday] 634616d0f9Sopenharmony_ci 644616d0f9Sopenharmony_ci %G is replaced by the ISO 8601 year with century as a decimal 654616d0f9Sopenharmony_ci number. See also the %V conversion specification. [tm_year, 664616d0f9Sopenharmony_ci tm_yday, tm_wday] 674616d0f9Sopenharmony_ci 684616d0f9Sopenharmony_ci %g is replaced by the ISO 8601 year without century as a decimal 694616d0f9Sopenharmony_ci number [00,99]. This is the year that includes the greater part 704616d0f9Sopenharmony_ci of the week. (Monday as the first day of a week). See also the 714616d0f9Sopenharmony_ci %V conversion specification. [tm_year, tm_yday, tm_wday] 724616d0f9Sopenharmony_ci 734616d0f9Sopenharmony_ci %H is replaced by the hour (24-hour clock) as a decimal number 744616d0f9Sopenharmony_ci [00,23]. [tm_hour] 754616d0f9Sopenharmony_ci 764616d0f9Sopenharmony_ci %I is replaced by the hour (12-hour clock) as a decimal number 774616d0f9Sopenharmony_ci [01,12]. [tm_hour] 784616d0f9Sopenharmony_ci 794616d0f9Sopenharmony_ci %j is replaced by the day of the year as a decimal number 804616d0f9Sopenharmony_ci [001,366]. [tm_yday] 814616d0f9Sopenharmony_ci 824616d0f9Sopenharmony_ci %k is replaced by the hour (24-hour clock) as a decimal number 834616d0f9Sopenharmony_ci [0,23]; single digits are preceded by a blank. [tm_hour] 844616d0f9Sopenharmony_ci 854616d0f9Sopenharmony_ci %l is replaced by the hour (12-hour clock) as a decimal number 864616d0f9Sopenharmony_ci [1,12]; single digits are preceded by a blank. [tm_hour] 874616d0f9Sopenharmony_ci 884616d0f9Sopenharmony_ci %M is replaced by the minute as a decimal number [00,59]. [tm_min] 894616d0f9Sopenharmony_ci 904616d0f9Sopenharmony_ci %m is replaced by the month as a decimal number [01,12]. [tm_mon] 914616d0f9Sopenharmony_ci 924616d0f9Sopenharmony_ci %n is replaced by a newline. 934616d0f9Sopenharmony_ci 944616d0f9Sopenharmony_ci %p is replaced by the locale's equivalent of either "AM" or "PM". 954616d0f9Sopenharmony_ci [tm_hour] 964616d0f9Sopenharmony_ci 974616d0f9Sopenharmony_ci %R is replaced by the time in the format %H:%M. [tm_hour, tm_min] 984616d0f9Sopenharmony_ci 994616d0f9Sopenharmony_ci %r is replaced by the locale's representation of 12-hour clock time 1004616d0f9Sopenharmony_ci using AM/PM notation. [tm_hour, tm_min, tm_sec] 1014616d0f9Sopenharmony_ci 1024616d0f9Sopenharmony_ci %S is replaced by the second as a decimal number [00,60]. The 1034616d0f9Sopenharmony_ci range of seconds is [00,60] instead of [00,59] to allow for the 1044616d0f9Sopenharmony_ci periodic occurrence of leap seconds. [tm_sec] 1054616d0f9Sopenharmony_ci 1064616d0f9Sopenharmony_ci %s is replaced by the number of seconds since the Epoch (see 1074616d0f9Sopenharmony_ci ctime(3)). Although %s is reliable in this implementation, it 1084616d0f9Sopenharmony_ci can have glitches on other platforms (notably platforms lacking 1094616d0f9Sopenharmony_ci tm_gmtoff), so portable code should format a time_t value 1104616d0f9Sopenharmony_ci directly via something like sprintf instead of via localtime 1114616d0f9Sopenharmony_ci followed by strftime with "%s". [tm_year, tm_mon, tm_mday, 1124616d0f9Sopenharmony_ci tm_hour, tm_min, tm_sec, tm_gmtoff+, tm_isdst-]. 1134616d0f9Sopenharmony_ci 1144616d0f9Sopenharmony_ci %T is replaced by the time in the format %H:%M:%S. [tm_hour, 1154616d0f9Sopenharmony_ci tm_min, tm_sec] 1164616d0f9Sopenharmony_ci 1174616d0f9Sopenharmony_ci %t is replaced by a tab. 1184616d0f9Sopenharmony_ci 1194616d0f9Sopenharmony_ci %U is replaced by the week number of the year (Sunday as the first 1204616d0f9Sopenharmony_ci day of the week) as a decimal number [00,53]. [tm_wday, 1214616d0f9Sopenharmony_ci tm_yday, tm_year-] 1224616d0f9Sopenharmony_ci 1234616d0f9Sopenharmony_ci %u is replaced by the weekday (Monday as the first day of the week) 1244616d0f9Sopenharmony_ci as a decimal number [1,7]. [tm_wday] 1254616d0f9Sopenharmony_ci 1264616d0f9Sopenharmony_ci %V is replaced by the week number of the year (Monday as the first 1274616d0f9Sopenharmony_ci day of the week) as a decimal number [01,53]. If the week 1284616d0f9Sopenharmony_ci containing January 1 has four or more days in the new year, then 1294616d0f9Sopenharmony_ci it is week 1; otherwise it is week 53 of the previous year, and 1304616d0f9Sopenharmony_ci the next week is week 1. The year is given by the %G conversion 1314616d0f9Sopenharmony_ci specification. [tm_year, tm_yday, tm_wday] 1324616d0f9Sopenharmony_ci 1334616d0f9Sopenharmony_ci %W is replaced by the week number of the year (Monday as the first 1344616d0f9Sopenharmony_ci day of the week) as a decimal number [00,53]. [tm_yday, 1354616d0f9Sopenharmony_ci tm_wday] 1364616d0f9Sopenharmony_ci 1374616d0f9Sopenharmony_ci %w is replaced by the weekday (Sunday as the first day of the week) 1384616d0f9Sopenharmony_ci as a decimal number [0,6]. [tm_year, tm_yday, tm_wday] 1394616d0f9Sopenharmony_ci 1404616d0f9Sopenharmony_ci %X is replaced by the locale's appropriate time representation. 1414616d0f9Sopenharmony_ci [tm_year-, tm_yday-, tm_mon-, tm_mday-, tm_wday-, tm_hour, 1424616d0f9Sopenharmony_ci tm_min, tm_sec, tm_gmtoff+, tm_zone+, tm_isdst-]. 1434616d0f9Sopenharmony_ci 1444616d0f9Sopenharmony_ci %x is replaced by the locale's appropriate date representation. 1454616d0f9Sopenharmony_ci [tm_year, tm_yday, tm_mon, tm_mday, tm_wday, tm_hour-, tm_min-, 1464616d0f9Sopenharmony_ci tm_sec-, tm_gmtoff-, tm_zone-, tm_isdst-]. 1474616d0f9Sopenharmony_ci 1484616d0f9Sopenharmony_ci %Y is replaced by the year with century as a decimal number. 1494616d0f9Sopenharmony_ci [tm_year] 1504616d0f9Sopenharmony_ci 1514616d0f9Sopenharmony_ci %y is replaced by the year without century as a decimal number 1524616d0f9Sopenharmony_ci [00,99]. [tm_year] 1534616d0f9Sopenharmony_ci 1544616d0f9Sopenharmony_ci %Z is replaced by the time zone abbreviation, or by the empty 1554616d0f9Sopenharmony_ci string if this is not determinable. [tm_zone+, tm_isdst-] 1564616d0f9Sopenharmony_ci 1574616d0f9Sopenharmony_ci %z is replaced by the offset from the Prime Meridian in the format 1584616d0f9Sopenharmony_ci +HHMM or -HHMM (ISO 8601) as appropriate, with positive values 1594616d0f9Sopenharmony_ci representing locations east of Greenwich, or by the empty string 1604616d0f9Sopenharmony_ci if this is not determinable. The numeric time zone abbreviation 1614616d0f9Sopenharmony_ci -0000 is used when the time is Universal Time but local time is 1624616d0f9Sopenharmony_ci indeterminate; by convention this is used for locations while 1634616d0f9Sopenharmony_ci uninhabited, and corresponds to a zero offset when the time zone 1644616d0f9Sopenharmony_ci abbreviation begins with "-". [tm_gmtoff+, tm_zone+, tm_isdst-] 1654616d0f9Sopenharmony_ci 1664616d0f9Sopenharmony_ci %% is replaced by a single %. 1674616d0f9Sopenharmony_ci 1684616d0f9Sopenharmony_ci %+ is replaced by the locale's date and time in date(1) format. 1694616d0f9Sopenharmony_ci [tm_year, tm_yday, tm_mon, tm_mday, tm_wday, tm_hour, tm_min, 1704616d0f9Sopenharmony_ci tm_sec, tm_gmtoff, tm_zone] 1714616d0f9Sopenharmony_ci 1724616d0f9Sopenharmony_ci As a side effect, strftime also behaves as if tzset were called. This 1734616d0f9Sopenharmony_ci is for compatibility with older platforms, as required by POSIX; it is 1744616d0f9Sopenharmony_ci not needed for tzset's own use. 1754616d0f9Sopenharmony_ci 1764616d0f9Sopenharmony_ciRETURN VALUE 1774616d0f9Sopenharmony_ci If the conversion is successful, strftime returns the number of bytes 1784616d0f9Sopenharmony_ci placed into the array, not counting the terminating NUL; errno is 1794616d0f9Sopenharmony_ci unchanged if the returned value is zero. Otherwise, errno is set to 1804616d0f9Sopenharmony_ci indicate the error, zero is returned, and the array contents are 1814616d0f9Sopenharmony_ci unspecified. 1824616d0f9Sopenharmony_ci 1834616d0f9Sopenharmony_ciERRORS 1844616d0f9Sopenharmony_ci This function fails if: 1854616d0f9Sopenharmony_ci 1864616d0f9Sopenharmony_ci [ERANGE] 1874616d0f9Sopenharmony_ci The total number of resulting bytes, including the terminating 1884616d0f9Sopenharmony_ci NUL character, is more than maxsize. 1894616d0f9Sopenharmony_ci 1904616d0f9Sopenharmony_ci This function may fail if: 1914616d0f9Sopenharmony_ci 1924616d0f9Sopenharmony_ci [EOVERFLOW] 1934616d0f9Sopenharmony_ci The format includes an %s conversion and the number of seconds 1944616d0f9Sopenharmony_ci since the Epoch cannot be represented in a time_t. 1954616d0f9Sopenharmony_ci 1964616d0f9Sopenharmony_ciSEE ALSO 1974616d0f9Sopenharmony_ci date(1), getenv(3), newctime(3), newtzset(3), time(2), tzfile(5) 1984616d0f9Sopenharmony_ci 1994616d0f9Sopenharmony_ciBUGS 2004616d0f9Sopenharmony_ci There is no conversion specification for the phase of the moon. 2014616d0f9Sopenharmony_ci 2024616d0f9Sopenharmony_ciTime Zone Database newstrftime(3) 203