Format Description | Code Snippet | Output |
---|
Short date pattern (d) | DateTime.Now.ToString("d") | 11/8/2010 |
Long date pattern (D) | DateTime.Now.ToString("D") | Monday, November 08, 2010 |
Full date/time pattern - short time (f) | DateTime.Now.ToString("f") | Monday, November 08, 2010 3:39 PM |
Full date/time pattern - long time (F) | DateTime.Now.ToString("F") | Monday, November 08, 2010 3:39:46 PM |
General date/time pattern - short time (g) | DateTime.Now.ToString("g") | 11/8/2010 3:39 PM |
General date/time pattern - long time (G) | DateTime.Now.ToString("G") | 11/8/2010 3:39:46 PM |
Month/day pattern (M) | DateTime.Now.ToString("M") | November 08 |
Round-trip date/time pattern (O) | DateTime.Now.ToString("O") | 2010-11-08T15:39:46.4804000-08:00 |
RFC 1123 pattern (R) | DateTime.Now.ToString("R") | Mon, 08 Nov 2010 15:39:46 GMT |
Sortable date/time pattern (s) | DateTime.Now.ToString("s") | 2010-11-08T15:39:46 |
Short time pattern (t) | DateTime.Now.ToString("t") | 3:39 PM |
Long time pattern (T) | DateTime.Now.ToString("T") | 3:39:46 PM |
Universal sortable date/time pattern (u) | DateTime.Now.ToString("u") | 2010-11-08 15:39:46Z |
Universal full date/time pattern (U) | DateTime.Now.ToString("U") | Monday, November 08, 2010 11:39:46 PM |
Year/month pattern (Y) | DateTime.Now.ToString("Y") | November, 2010 |
Format Description | Code Snippet | Output |
---|
Currency with default precision (C) | 3.14159.ToString("C") | $3.14 |
Currency with specified precision (CN) | 3.14159.ToString("C4") | $3.1416 |
Decimal with default precision (D) | 32534.ToString("D") | 32534 |
Decimal with specified precision (DN) | 32534.ToString("D10") | 0000032534 |
Exponential (E) | 123456789.ToString("E") | 1.234568E+008 |
Fixed point with default precision (F) | 3.14159.ToString("F") | 3.14 |
Fixed point with specified precision (FN) | 3.14159.ToString("F4") | 3.1416 |
General with default precision (G) | 3.14159.ToString("G") | 3.14159 |
General with specified precision (GN) | 3.14159.ToString("G2") | 3.1 |
Number with default decimal places (N) | 3.14159.ToString("N") | 3.14 |
Number with specified decimal places (NN) | 3.14159.ToString("N3") | 3.142 |
Percent with default decimal places (P) | 0.8752.ToString("P") | 87.52 % |
Percent with specified decimal places (PN) | 0.8752.ToString("P0") | 88 % |
Round-trip (R) | 3.14159.ToString("R") | 3.14159 |
Hexadecimal (X) | 183.ToString("X") | B7 |
Format Description | Code Snippet | Output |
---|
Zero placeholder (0) | 3.14.ToString("00.0000") | 03.1400 |
Zero placeholder (0) | 123.45678.ToString("00.0000") | 123.4568 |
Digit (#) and zero (0) placeholders | 3.14.ToString("#0.000#") | 3.140 |
Digit (#) and zero (0) placeholders | 123.45678.ToString("#0.000#") | 123.4568 |
Group separator placeholder (,) | 123456.ToString("#,000.00") | 123,456.0 |
Group separator placeholder (,) | 123456789.ToString("#,000.00") | 123,456,789.0 |
Group separator placeholder (,) | 123456789876.ToString("#,000.00") | 123,456,789,876.0 |
Section separator (;) | 12345.67.ToString("#,000.00;(#,000.00);Zero") | 12,345.67 |
Section separator (;) | (-12345.67).ToString("#,000.00;(#,000.00);Zero") | (12,345.67) |
Section separator (;) | 0.ToString("#,000.00;(#,000.00);Zero") | Zero |
Format Description | Code Snippet | Output |
---|
Abbreviated format (less than 1,000) | 34.ToAbbreviatedFormat() | 34 |
Abbreviated format (greater than 1,000) | 9876.ToAbbreviatedFormat() | 9k |
Abbreviated format (greater than 1,000) | 12345678.ToAbbreviatedFormat() | 12,345k |
To string as text (capitalized) | 3.ToStringAsText(true) | Three |
To string as text (not capitalized) | 6.ToStringAsText(false) | six |
To string as text (greater than 10) | 1234.ToStringAsText(false) | 1,234 |