# Format Flags

Many of the format flags this new system uses for output are those used by `strftime(...)`, but not all. Some new flags have been added, and others overridden. The input system supports only specific flags, therefore, not all flags that work for output will work with input (we are currently working to correct this situation).

The following tables list the all the flags available for both date_time IO as well as strftime. Format flags marked with a single asterisk (*) have a behavior unique to date_time. Those flags marked with an exclamation point (!) are not usable for input (at this time). The flags marked with a hash sign (#) are implemented by system locale and are known to be missing on some platforms. The first table is for dates, and the second table is for times.

Date Facet Format Flags

Format Specifier | Description
--- | ---
Example

    %a

Abbreviated weekday name

    "Mon" => Monday

    %A

Long weekday name

    "Monday"

    %b

Abbreviated month name

    "Feb" => February

    %B

Full month name

    "February"

    %c !

The preferred date and time representation for the current locale.

    %C !#

The century number (year/100) as a 2-digit integer.

    %d

Day of the month as decimal 01 to 31. When used to parse input, the leading zero is optional.

    %D !#

Equivalent to %m/%d/%y

    %e #

Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space. When used to parse input, the leading space is optional.

    %G !

This has the same format and value as %y, except that if the ISO week number belongs to the previous or next year, that year is used instead.

    %g !

Like %G, but without century.

    %h !#

Equivalent to %b

    %j

Day of year as decimal from 001 to 366 for leap years, 001 - 365 for non-leap years.

    "060" => Feb-29

    %m

Month name as a decimal 01 to 12

    "01" => January

    %u !

The day of the week as a decimal, range 1 to 7, Monday being 1.

    %U

The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. In 2005, Jan 1st falls on a Saturday, so therefore it falls within week 00 of 2005 (week 00 spans 2004-Dec-26 to 2005-Jan-01. This also happens to be week 53 of 2004).

    date d(2005, Jan, 1); // Saturday
    // with format %U
    ss << d; // "00"
    d += day(1); // Sunday
    ss << d; // "01" beginning of week 1

    %V !#

The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.

    %w

Weekday as decimal number 0 to 6

    "0" => Sunday

    %W

Week number 00 to 53 where Monday is first day of week 1

    date d(2005, Jan, 2); // Sunday
    // with format %W
    ss << d; // "00"
    d += day(1); // Monday
    ss << d; // "01" beginning of week 1

    %x

Implementation defined date format from the locale.

    date d(2005,Oct,31);
    date_facet* f = new date_facet("%x");

    locale loc = locale(locale("en_US"), f);
    cout.imbue(loc);
    cout << d; // "10/31/2005"

    loc = locale(locale("de_DE"), f);
    cout.imbue(loc);
    cout << d; // "31.10.2005"

    %y

Two digit year

    "05" => 2005

    %Y

Four digit year

    "2005"

    %Y-%b-%d

Default date format

    "2005-Apr-01"

    %Y%m%d

ISO format

    "20050401"

    %Y-%m-%d

ISO extended format

    "2005-04-01"

Time Facet Format Flags

Format Specifier | Description
--- | ---
Example

    %- *!

Placeholder for the sign of a duration. Only displays when the duration is negative.

    "-13:15:16"

    %+ *!

Placeholder for the sign of a duration. Always displays for both positive and negative.

    "+13:15:16"

    %f

Fractional seconds are always used, even when their value is zero

    "13:15:16.000000"

    %F *

Fractional seconds are used only when their value is not zero.

    "13:15:16"
    "05:04:03.001234"

    %H

The hour as a decimal number using a 24-hour clock (range 00 to 23).

    %I !

The hour as a decimal number using a 12-hour clock (range 01 to 12).

    %k !

The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank.

    %l !

The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank.

    %M

The minute as a decimal number (range 00 to 59).

    %O

The number of hours in a time duration as a decimal number (range 0 to max. representable duration); single digits are preceded by a zero.

    %p !

Either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale.

    %P !#

Like %p but in lowercase: `am' or `pm' or a corresponding string for the current locale.

    %r !#

The time in a.m. or p.m. notation. In the POSIX locale this is equivalent to `%I:%M:%S %p'

    %R !

The time in 24-hour notation (%H:%M)

    %s *

Seconds with fractional seconds.

    "59.000000"

    %S

Seconds only

    "59"

    %T !

The time in 24-hour notation (%H:%M:%S)

    %q

ISO time zone (output only). This flag is ignored when using the time_facet with a ptime.

    "-0700" // Mountain Standard Time

    %Q

ISO extended time zone (output only). This flag is ignored when using the time_facet with a ptime.

    "-05:00" // Eastern Standard Time

    %z *!

Abbreviated time zone (output only). This flag is ignored when using the time_facet with a ptime.

    "MST" // Mountain Standard Time

    %Z *!

Full time zone name (output only). This flag is ignored when using the time_facet with a ptime.

    "EDT" // Eastern Daylight Time

    %ZP *

Posix time zone string (available to both input and output). This flag is ignored when using the time_facet with a ptime. For complete details on posix time zone strings, see posix_time_zone class.

    "EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"

    %x %X

Implementation defined date/time format from the locale.

    date d(2005,Oct,31);
    ptime pt(d, hours(20));
    time_facet* f = new time_facet("%x %X");

    locale loc = locale(locale("en_US"), f);
    cout.imbue(loc);
    cout << pt; // "10/31/2005 08:00:00 PM"

    loc = locale(locale("de_DE"), f);
    cout.imbue(loc);
    cout << pt; // "31.10.2005 20:00:00"

    %Y%m%dT%H%M%S%F%q

ISO format

    "20051015T131211-0700" // Oct 15, 2005 13:12:11 MST

    %Y-%m-%d %H:%M:%S%F%Q

Extended ISO format

    "2005-10-15 13:12:11-07:00"

    %Y-%b-%d %H:%M:%S%F %z

Default format used when outputting ptime and local_date_time.

    "2005-Oct-15 13:12:11 MST"

    %Y-%b-%d %H:%M:%S%F %ZP

Default format used when inputting ptime and local_date_time.

    "2005-Oct-15 13:12:11 MST-07"

    %-%H:%M:%S%F !

Default time_duration format for output. Sign will only be displayed for negative durations.

    "-13:14:15.003400"

    %H:%M:%S%F

Default time_duration format for input.

    "13:14:15.003400"

* Signifies flags that have a behavior unique to `date_time`.

# Signifies flags that have a platform-dependent behavior. These may not be supported everywhere.

! Signifies flags that currently do not work for input.