This is often used to format strings of dates and numbers, so we sorted out some of the help items here.
The following table describes the standard format specifiers used to format datetime objects.
Format description
D short date mode
D. Long date mode
T short time mode
T long time mode
F full date/time mode (Short Time)
F full date/time mode (long time)
G regular date/time mode (Short Time)
G regular date/time mode (long time)
C # format the value result table
Character |
Description |
Example |
Output |
C |
Currency |
String. Format("{0: C3}", 2) |
$2.000 |
D |
Decimal |
String. Format("{0: D3}", 2) |
002 |
E |
Scientific notation |
1.20e + 001 |
1.20e + 001 |
G |
General |
String. Format("{0: g}", 2) |
2 |
N |
Number separated by semicolons |
String. Format("{0: n}", 250000) |
250,000.00 |
X |
Hexadecimal |
String. Format("{0: x000}", 12) |
C |
|
|
String. Format("{0. 000}", 12.2) |
012.200 |
Specifier |
Type |
Example (passed system. datetime. Now) |
D |
Short date |
10/12/2002 |
D |
Long date |
December 10,200 2 |
T |
Short Time |
10: 11 pm |
T |
Long time |
10:11:29 |
F |
Full Date & time |
December 10,200 2 pm |
F |
Full Date & time (long) |
December 10,200 2 10:11:29 |
G |
Default Date & time |
10/12/2002 pm |
G |
Default Date & time (long) |
10/12/2002 10:11:29 |
M |
Month day Pattern |
December 10 |
R |
Rfc1123 date string |
Tue, 10 Dec 2002 22:11:29 GMT |
S |
Sortable date string |
2002-12-10t22: 11: 29 |
U |
Universal sortable, local time |
2002-12-10 22: 13: 50z |
U |
Universal sortable, GMT |
December 11,200 2 3:13:50 AM |
Y |
Year month pattern |
December 2002 |
Custom date formatting:
Specifier |
Type |
Example |
Example output |
Dd |
Day |
{0: dd} |
10 |
Ddd |
Day name |
{0: DDD} |
Tue |
Dddd |
Full day name |
{0: dddd} |
Tuesday |
F, FF ,... |
Second Fractions |
{0: fff} |
932 |
GG ,... |
Era |
{0: Gg} |
A.D. |
HH |
2 digit hour |
{0: hh} |
10 |
HH |
2 digit hour, 24hr format |
{0: hh} |
22 |
Mm |
Minute 00-59 |
{0: mm} |
38 |
Mm |
Month 01-12 |
{0: mm} |
12 |
Mmm |
Month abbreviation |
{0: Mmm} |
Dec |
Mmmm |
Full month name |
{0: Mmmm} |
December |
SS |
Seconds 00-59 |
{0: SS} |
46 |
TT |
AM or PM |
{0: TT} |
PM |
YY |
Year, 2 digits |
{0: yy} |
02 |
Yyyy |
Year |
{0: yyyy} |
2002 |
Zz |
Timezone offset, 2 digits |
{0: ZZ} |
-05 |
Zzz |
Full timezone offset |
{0: ZZZ} |
-05:00 |
: |
Separator |
{0: hh: mm: SS} |
10:43:20 |
/ |
Separator |
{0: dd/mm/yyyy} |
10/12/2002 |
String. Format Method
Replace each format item in the specified string with the text equivalent item of the value of the corresponding object.
Name |
Description |
String. Format (string, object) |
StringReplace the format item with the text equivalent of the value of the specified object instance. Supported by. NET Compact framework. |
String. Format (string, object []) |
SpecifyStringTo replace the format items in the specified arrayObjectText equivalent of the Instance value. Supported by. NET Compact framework. |
String. Format (iformatprovider, String, object []) |
SpecifyStringTo replace the format items in the specified arrayObjectText equivalent of the Instance value. The specified parameter specifies the format of the region. Supported by. NET Compact framework. |
String. Format (string, object, object) |
StringReplace the format items with two specifiedObjectText equivalent of the Instance value. Supported by. NET Compact framework. |
String. Format (string, object) |
StringReplace the format items with the three specifiedObjectText equivalent of the Instance value. Supported by. NET Compact framework. |
Copy yourself as an online backup post