James Ray Anderson

James Ray Anderson
James Ray Anderson
0 comments

Handy String Format Types

11:25 AM
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.

Specifier          TypeFormatExample (1500)
cCurrency{0:c}$1500.00
dDecimal{0:d}1500.00
fFixed Point{0:f}1500.00 
gGeneral Number{0:g}1500.00
nNumber with Commas{0:n}1,500.00
xHexadecimal{0:x4}5dc
zero 0Zero 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    TypeFormat01/01/2011 11:05:01 PM
: or /Separators{0:dd/MM/yyyy hh:mm:ss}01/01/2011 11:05:01
dShort Date{0:d}01/01/2011
DLong Date{0:D}January 01, 2011
tShort Time{0:t}11:05 PM
TLong Time{0:T}11:05:01 PM
fFull date and time{0:f}January 01, 2011 11:05 PM
FFull date and time (long){0:F}January 01, 2011 11:05:01 PM
MMMonth{0:MM}01
MMMMonth (short){0:MMM}Jan
MMMMMonth (full){0:MMMM}January
ddDay{0:dd}01
dddDay Name{0:ddd}Sat
ddddDay Name (full){0:dddd}Saturday
yy2-Digit year{0:yy}11
yyyy4-Digit Year{0:YY}2011
MMonth-Day{0:M}January 01
YMonth-Year{0:Y}January, 2011
sSortable date string{0:s}2011-01-01T23:05:01
ggEra{0:gg}A.D.
hh2-Digit Hour (12 hour format){0:hh}11
HH2-Digit Hour (24-hour format){0:HH}23
mmMinute{0:mm}05
ssSeconds{0:ss}01
ttAM or PM{0:tt}PM

0 comments:

 
Toggle Footer
Top