The format string supported by the format (-f
) operator is a string that contains
format items. Each format item takes the form of:
<
index
>
represents the zero-based index of the
item in the object array following the format operator.
<
alignment
>
is optional, and represents the
alignment of the item. A positive number aligns the item to the right
of a field of the specified width. A negative number aligns the item
to the left of a field of the specifed width.
<formatString>
is
optional, and formats the item using to that type’s specific format
string syntax (as laid out below.)
All format specifiers may be followed by a number between 0 and 99 to control the precision of the formatting.
Standard Numeric Format Strings | |||
---|---|---|---|
Format Specifier | Name | Description | Example |
| Currency | A currency amount. | |
| Decimal | A decimal amount (for integral types.) The precision specifier controls the minimum number of digits in the result. | |
| Scientific | Scientific (exponential) notation. The precision specifier controls the number of digits past the decimal point. | |
| Fixed-point | Fixed point notation. The precision specifier controls the number of digits past the decimal point. | |
| General | The most compact representation (between fixed point and scientific) of the number. The precision specifier controls the number of significant digits. | |
| Number | The human readable form of the number, which includes separators between number groups. The precision specifier controls the number of digits past the decimal point. | |
| Percent | The number (generally between 0 and 1) represented as a percentage. The precision specifier controls the number of digits past the decimal point. | |
| Round-trip | The Single or Double number formatted with a precision that guarantees the string (when parsed) will result in the original number again. | |
| Hexidecimal | The number converted to a string of hexadecimal digits. The case of the specifier controls the case of the resulting hexadecimal digits. The precision specifier controls the minimum number of digits is the resulting string. |
You may use custom numeric strings to format numbers in ways not supported by the standard format strings.
Custom Numeric Format Strings | |||
---|---|---|---|
Format Specifier | Name | Description | Example |
| Zero placeholder | Specifies the precision and width of a number string. Zeroes not matched by digits in the original number are output as zeroes. | |
| Digit placeholder | Specifies the precision and width of a number string. # symbols not matched by digits in the input number are not output. | |
| Decimal point | Determines the location of the decimal separator. | |
| Thousands separator | When placed between a zero or digit placeholder before the decimal point in a formatting string, adds the separator character between number groups. | |
| Number scaling | When placed before the literal (or implicit) decimal point in a formatting string, divides the input by 1000. You may apply this format specifier more than once. | |
| Percentage placeholder | Multiplies the input by 100, and inserts the percent sign where shown in the format specifier. | |
Scientific notation | Displays the input in scientific notation. The number of zeroes that follow the E define the minimum length of the exponent field. | ||
Literal string | Inserts the provided text literally into the output without affecting formatting. | ||
| Section separator | Allows for conditional formatting. If your format specifier contains no section separators, then the formatting statement applies to all input. If your format specifier contains one separator (creating two sections,) then the first section applies to positive numbers and zero. The second section applies to negative numbers. If your format specifier contains two separators (creating three sections,) then the sections apply to positive numbers, negative numbers, and zero. | |
Other | Other character | Inserts the provided text literally into the output without affecting formatting. |
Converts a DateTime object to one of several standard formats.
Standard DateTime Format Strings | |||
---|---|---|---|
Format Specifier | Name | Description | Example |
| Short date | The culture’s short date format. | |
| Long date | The culture’s long date format. | |
| Full date / short time | Combines the long date and short time format patterns. | |
| Full date / long time | Combines the long date and long time format patterns. | |
| General date / short time | Combines the short date and short time format patterns. | |
| General date / long time | Combines the short date and long time format patterns. | |
| Month day | The culture’s MonthDay format. | |
| Round-trip date / time | The date formatted with a pattern that guarantees the string (when parsed) will result in the original DateTime again. | |
| RFC1123 | The standard RFC1123 format pattern. | |
| Sortable | Sortable format pattern. Conforms to ISO 8601, and provides output suitable for sorting. | |
| Short time | The culture’s ShortTime format. | |
| Long time | The culture’s LongTime format. | |
| Universal sortable | The culture’s UniversalSortableDateTime format applied to the UTC equivalent of the input. | |
| Universal sortable | The culture’s FullDateTime format applied to the UTC equivalent of the input. | |
| Year month | The culture’s YearMonth format. |
You may use custom DateTime format strings to format dates in ways not supported by the standard format strings. Note: single-character format specifiers are interpreted as a standard DateTime formatting string unless used with other formatting specifiers.
Custom DateTime Format Strings | ||
---|---|---|
Format Specifier | Description | Example |
| Day of the month as a number between 1 and 31. Represents single-digit days without a leading zero. | |
| Day of the month as a number between 1 and 31. Represents single-digit days with a leading zero. | |
| Abbreviated name of the day of week. | |
| Full name of the day of the week. | |
| Most significant digit of the seconds fraction | |
| Two most significant digit of the seconds fraction. | |
| Three most significant digit of the seconds fraction. | |
| Four most significant digit of the seconds fraction. | |
| Five most significant digit of the seconds fraction. | |
| Six most significant digit of the seconds fraction. | |
| Seven most significant digit of the seconds fraction. | |
| Most significant digit of the seconds fraction. Displays nothing if the number is zero. | |
| Two most significant digit of the seconds fraction. Displays nothing if the number is zero. | |
| Three most significant digit of the seconds fraction. Displays nothing if the number is zero. | |
| Four most significant digit of the seconds fraction. Displays nothing if the number is zero. | |
| Five most significant digit of the seconds fraction. Displays nothing if the number is zero. | |
| Six most significant digit of the seconds fraction. Displays nothing if the number is zero. | |
| Seven most significant digit of the seconds fraction. Displays nothing if the number is zero. | |
| Era (i.e., A.D) | |
| Hours, as a number between 1 and 12. Single digits do not include a leading zero. | |
| Hours, as a number between 01 and 12. Single digits include a leading zero. Note: this is interpreted as a standard DateTime formatting string unless used with other formatting specifiers. | |
| Hours, as a number between 0 and 23. Single digits do not include a leading zero. | |
| Hours, as a number between 00 and 23. Single digits include a leading zero. | |
| DateTime.Kind specifier that corresponds to the kind (ie: Local, Utc, or Unspecified) of input date. | |
| Minute, as a number between 0 and 59. Single digits do not include a leading zero. | |
| Minute, as a number between 00 and 59. Single digits include a leading zero. | |
| Month, as a number between 1 and 12. Single digits do not include a leading zero. | |
| Month, as a number between 01 and 12. Single digits include a leading zero. | |
| Abbreviated month name. | |
| Full month name. | |
| Seconds, as a number between 0 and 59. Single digits do not include a leading zero. | |
| Seconds, as a number between 00 and 59. Single digits include a leading zero. | |
| First character of the A.M. / P.M. designator. | |
| A.M. / P.M designator. | |
| Year, in (at most) 2 digits. | |
| Year, in (at most) 3 digits. | |
| Year, in (at most) 4 digits. | |
| Year, in (at most) 5 digits. | |
| Signed time zone offset from GMT. Does not include a leading zero. | |
| Signed time zone offset from GMT. Includes a leading zero. | |
| Signed time-zone offset from GMT, measured in hours and minutes. | |
| Time separator. | |
| Date separator. | |
Inserts the provided text literally into the output without affecting formatting. | ||
| Syntax allowing for single-character custom formatting specifiers. The % sign is not added to the output. | |
Other | Inserts the provided text literally into the output without affecting formatting. |
3.133.12.172