These commands follow largely from the C90 and C99 standards. However a major difference here is that most of the commands have meaning for parsing as well as formatting, whereas the C standard only uses these commands for formatting. The pattern string consists of zero or more conversion specifiers and ordinary characters (char or wchar_t). A conversion specifier consists of a % character, possibly followed by an E or O modifier character (described below), followed by a character that determines the behavior of the conversion specifier. Ordinary characters (non-conversion specifiers) must appear in the source string during parsing in the appropriate place or failbit gets set. On formatting, ordinary characters are sent to the output stream unmodified.
The E modifier can appear on any conversion specifier. But it is ignored for both parsing and formatting.
The O modifier can appear on any conversion specifier. It is ignored for parsing, but effects the following conversion specifiers on output by not inserting leading zeroes: %C, %d, %D, %F, %g, %H, %I, %j, %m, %M, %S, %U, %V, %W, %y
| Modifier | Parse | Format |
|---|---|---|
| %a | Reads one of the locale's weekday names. The name can either be the full name, or the abbreviated name. Case is significant. On successful parsing of one of the weekday names, sets tm_wday, otherwise sets failbit. For parsing, this format is identical to %A. | Outputs the locale's abbreviated weekday name as specified by tm_wday. The "C" locale's abbreviated weekday names are: Sun, Mon, Tue, Wed, Thu, Fri, Sat. |
| %A | For parsing, this format is identical to %a. | Outputs the locale's full weekday name as specified by tm_wday. The "C" locale's full weekday names are: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday. |
| %b | Reads one of the locale's month names. The name can either be the full name, or the abbreviated name. Case is significant. On successful parsing of one of the month names, sets tm_mon, otherwise sets failbit. For parsing, this format is identical to %B. | Outputs the locale's abbreviated month name as specified by tm_mon. The "C" locale's abbreviated month names are: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec. |
| %B | For parsing, this format is identical to %b. | Outputs the locale's full month name as specified by tm_mon. The "C" locale's full month names are: January, February, March, April, May, June, July, August, September, October, November, December. |
| %c | Reads the date-and-time as specified by the current locale. The "C" locale specification is "%A %B %d %T %Y". On successful parsing this sets tm_wday, tm_mon, tm_mday, tm_sec, tm_min, tm_hour and tm_year. If the entire pattern is not successfully parsed, then no tm members are set and failbit is set. | Outputs the locale's date-and-time. The "C" locale's date-and-time format is "%A %B %d %T %Y". This information is specified by tm_wday, tm_mon, tm_mday, tm_sec, tm_min, tm_hour and tm_year. |
| %C | This is not a valid parse format. If %C is used in a parse pattern, a runtime_error is thrown. | Outputs the current year divided by 100. Single digit results will be pre-appended with '0' unless the O modifier is used. |
| %d | Reads the day of the month. The result must be in the range [1, 31] else failbit will be set. Upon successful parsing tm_mday is set. For parsing, this format is identical to %e. | Outputs the day of the month as specified by tm_mday. Single digit results will be pre-appended with '0' unless the O modifier is used. |
| %D | Is equivalent to "%m/%d/%y". | Is equivalent to "%m/%d/%y". If the O modifier is used, is equivalent to "%Om/%Od/%y". |
| %e | Reads the day of the month. The result must be in the range [1, 31] else failbit will be set. Upon successful parsing tm_mday is set. For parsing, this format is identical to %d. | Outputs the day of the month as specified by tm_mday. Single digit results will be pre-appended with a space. |
| %F | Is equivalent to "%Y-%m-%d" (the ISO 8601 date format). | Is equivalent to "%Y-%m-%d". If the O modifier is used, is equivalent to "%Y-%Om-%Od". |
| %g | This is not a valid parse format. If %g is used in a parse pattern, a runtime_error is thrown. | Outputs the last 2 digits of the ISO 8601 week-based year. Single digit results will be pre-appended with '0' unless the O modifier is used. Specified by tm_year, tm_wday and tm_yday. |
| %G | This is not a valid parse format. If %G is used in a parse pattern, a runtime_error is thrown. | Outputs the ISO 8601 week-based year. Specified by tm_year, tm_wday and tm_yday. |
| %h | Is equivalent to %b. | Is equivalent to %b. |
| %H | Reads the hour (24-hour clock) as a decimal number. The result must be in the range [0, 23] else failbit will be set. Upon successful parsing tm_hour is set. | Outputs the hour (24-hour clock) as specified by tm_hour. Single digit results will be pre-appended with '0' unless the O modifier is used. |
| %I | Reads the hour (12-hour clock) as a decimal number. The result must be in the range [1, 12] else failbit will be set. Upon successful parsing tm_hour is set. This format is usually used with %p to specify am/pm. If a %p is not parsed with the %I, am is assumed. | Outputs the hour (12-hour clock) as specified by tm_hour. Single digit results will be pre-appended with '0' unless the O modifier is used. |
| %j | This is not a valid parse format. If %j is used in a parse pattern, a runtime_error is thrown. | Outputs the day of the year as specified by tm_yday in the range [001, 366]. If the O modifier is used, leading zeroes are suppressed. |
| %m | Reads the month as a decimal number. The result must be in the range [1, 12] else failbit will be set. Upon successful parsing tm_mon is set. | Outputs the month as specified by tm_mon as a decimal number in the range [1, 12]. Single digit results will be pre-appended with '0' unless the O modifier is used. |
| %M | Reads the minute as a decimal number. The result must be in the range [0, 59] else failbit will be set. Upon successful parsing tm_min is set. | Outputs the minute as specified by tm_min as a decimal number in the range [0, 59]. Single digit results will be pre-appended with '0' unless the O modifier is used. |
| %n | Is equivalent to '\n'. A newline must appear in the source string at this position else failbit will be set. | Is equivalent to '\n'. A newline is output. |
| %p | Reads the locale's designation for am or pm. If neither of these strings are parsed then failbit will be set. A successful read will modify tm_hour, but only if %I is successfully parsed in the same parse pattern. | Outputs the locale's designation for am or pm, depending upon the value of tm_hour. The "C" locale's designations are am and pm. |
| %r | Reads the 12-hour time as specified by the current locale. The "C" locale specification is "%I:%M:%S %p". On successful parsing this sets tm_hour, tm_min, and tm_sec. If the entire pattern is not successfully parsed, then no tm members are set and failbit is set. | Outputs the locale's 12-hour time. The "C" locale's date-and-time format is "%I:%M:%S %p". This information is specified by tm_hour, tm_min, and tm_sec. |
| %R | Is equivalent to "%H:%M". | Is equivalent to "%H:%M". If the O modifier is used, is equivalent to "%OH:%M". |
| %S | : Reads the second as a decimal number. The result must be in the range [0, 60] else failbit will be set. Upon successful parsing tm_sec is set. | Outputs the second as specified by tm_sec as a decimal number in the range [0, 60]. Single digit results will be pre-appended with '0' unless the O modifier is used. |
| %t | Is equivalent to '\t'. A tab must appear in the source string at this position else failbit will be set. | Is equivalent to '\t'. A tab is output. |
| %T | Is equivalent to "%H:%M:%S". | Is equivalent to "%H:%M:%S". If the O modifier is used, is equivalent to "%OH:%M:%S". |
| %u | Reads the ISO 8601 weekday as a decimal number [1, 7], where Monday is 1. If the result is outside the range [1, 7] failbit will be set. Upon successful parsing tm_wday is set. | Outputs tm_wday as the ISO 8601 weekday in the range [1, 7] where Monday is 1. |
| %U | This is not a valid parse format. If %U is used in a parse pattern, a runtime_error is thrown. | Outputs the week number of the year (the first Sunday as the first day of week 1) as a decimal number in the range [00, 53] using tm_year, tm_wday and tm_yday. If the O modifier is used, any leading zero is suppressed. |
| %V | This is not a valid parse format. If %V is used in a parse pattern, a runtime_error is thrown. | Outputs the ISO 8601 week-based year week number in the range [01, 53]. Specified by tm_year, tm_wday and tm_yday. If the O modifier is used, any leading zero is suppressed. |
| %w | Reads the weekday as a decimal number [0, 6], where Sunday is 0. If the result is outside the range [0, 6] failbit will be set. Upon successful parsing tm_wday is set. | Outputs tm_wday as the weekday in the range [0, 6] where Sunday is 0. |
| %W | This is not a valid parse format. If %W is used in a parse pattern, a runtime_error is thrown. | Outputs the week number in the range [00, 53]. Specified by tm_year, tm_wday and tm_yday. The first Monday as the first day of week 1. If the O modifier is used, any leading zero is suppressed. |
| %x | Reads the date as specified by the current locale. The "C" locale specification is "%A %B %d %Y". On successful parsing this sets tm_wday, tm_mon, tm_mday, and tm_year. If the entire pattern is not successfully parsed, then no tm members are set and failbit is set. | Outputs the locale's date. The "C" locale's date format is "%A %B %d %Y". This information is specified by tm_wday, tm_mon, tm_mday, and tm_year. |
| %X | Reads the time as specified by the current locale. The "C" locale specification is "%H:%M:%S". On successful parsing this sets tm_hour, tm_min, and tm_sec. If the entire pattern is not successfully parsed, then no tm members are set and failbit is set. | Outputs the locale's time. The "C" locale's time format is "%H:%M:%S". This information is specified by tm_hour, tm_min, and tm_sec. |
| %y | Reads the year as a 2 digit number. The century is specified by the locale. The "C" locale specification is 20 (the 21st century). On successful parsing this sets tm_year. If the year is not successfully parsed, then tm_year is not set and failbit is set. | Outputs the last two digits of tm_year. Single digit results will be pre-appended with '0' unless the O modifier is used. |
| %Y | Reads the year. On successful parsing this sets tm_year. If the year is not successfully parsed, then tm_year is not set and failbit is set. | Outputs the year as specified by tm_year. (e.g. 2001) |
| %z | Reads the offset from UTC in the ISO 8601 format ''-0430'' (meaning 4 hours 30 minutes behind UTC, west of Greenwich). Two strings are accepted according to the current locale, one indicating Daylight Savings Time is not in effect, the other indicating it is in effect. Depending upon which string is read, tm_isdst will be set to 0 or 1. If the locale's designations for these strings are zero length, then no parsing is done and tm_isdst is set to -1. If the locale has non-empty strings for the UTC offset and neither is successfully parsed, failbit is set. | Outputs the UTC offset according to the current locale and the setting of tm_isdst (if non-negative). The "C" locale's designation for these strings is "" (an empty string). |
| %Z | : Reads the time zone name. Two strings are accepted according to the current locale, one indicating Daylight Savings Time is not in effect, the other indicating it is in effect. Depending upon which string is read, tm_isdst will be set to 0 or 1. If the locale's designations for these strings are zero length, then no parsing is done and tm_isdst is set to -1. If the locale has non-empty strings for the time zone names and neither is successfully parsed, failbit is set. | Outputs the time zone according to the current locale and the setting of tm_isdst (if non-negative). The "C" locale's designation for these strings is "" (an empty string). |
| %% | A % must appear in the source string at this position else failbit will be set | A % is output. |
| % followed by a space | One or more white space characters are parsed in this position. White space is determined by the locale's ctype facet. If at least one white space character does not exist in this position, then failbit is set. | A space (' ') for output. |