Specifier | Type | Format | Example (1500) |
c | Currency | {0:c} | $1500.00 |
d | Decimal | {0:d} | 1500.00 |
f | Fixed Point | {0:f} | 1500.00 |
g | General Number | {0:g} | 1500.00 |
n | Number with Commas | {0:n} | 1,500.00 |
x | Hexadecimal | {0:x4} | 5dc |
zero 0 | Zero Placeholder | {0:00.0000} | 1500.0000 |
# | Digit Placeholder | {0:(#).## | (1500).00 |
. | Decimal Point | {0:0.0} | 1500.0 |
, | Thousand Separator | {0:0,0} | 1,500 |
% | Percent | {0:0%} | 1500% |
Specifier | Type | Format | 01/01/2011 11:05:01 PM |
: or / | Separators | {0:dd/MM/yyyy hh:mm:ss} | 01/01/2011 11:05:01 |
d | Short Date | {0:d} | 01/01/2011 |
D | Long Date | {0:D} | January 01, 2011 |
t | Short Time | {0:t} | 11:05 PM |
T | Long Time | {0:T} | 11:05:01 PM |
f | Full date and time | {0:f} | January 01, 2011 11:05 PM |
F | Full date and time (long) | {0:F} | January 01, 2011 11:05:01 PM |
MM | Month | {0:MM} | 01 |
MMM | Month (short) | {0:MMM} | Jan |
MMMM | Month (full) | {0:MMMM} | January |
dd | Day | {0:dd} | 01 |
ddd | Day Name | {0:ddd} | Sat |
dddd | Day Name (full) | {0:dddd} | Saturday |
yy | 2-Digit year | {0:yy} | 11 |
yyyy | 4-Digit Year | {0:YY} | 2011 |
M | Month-Day | {0:M} | January 01 |
Y | Month-Year | {0:Y} | January, 2011 |
s | Sortable date string | {0:s} | 2011-01-01T23:05:01 |
gg | Era | {0:gg} | A.D. |
hh | 2-Digit Hour (12 hour format) | {0:hh} | 11 |
HH | 2-Digit Hour (24-hour format) | {0:HH} | 23 |
mm | Minute | {0:mm} | 05 |
ss | Seconds | {0:ss} | 01 |
tt | AM or PM | {0:tt} | PM |
Handy String Format Types
After years of working with formatting data, here is a quick lookup table of the basic C# formatting nomenclature. Not all-inclusive...but the most popular ones.
0 comments:
Post a Comment