0% found this document useful (0 votes)
66 views1 page

Dot Net Formatting

The document provides reference information on standard numeric, date/time, and custom format strings in C# for formatting values. It includes tables listing common format specifiers for numeric, date/time, and GUID/enum values with descriptions and examples. Standard formats cover general, currency, percent, date, time and numeric formats. Custom formats allow specifying number of digits, placeholders, and scaling among other options.

Uploaded by

andrear77
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views1 page

Dot Net Formatting

The document provides reference information on standard numeric, date/time, and custom format strings in C# for formatting values. It includes tables listing common format specifiers for numeric, date/time, and GUID/enum values with descriptions and examples. Standard formats cover general, currency, percent, date, time and numeric formats. Custom formats allow specifying number of digits, placeholders, and scaling among other options.

Uploaded by

andrear77
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Standard Numeric Format Strings

Standard DateTime Format Strings

Format

Name

Precision

(int)1234

(double)123.456

Specifier

Name

Example Format

3 Dec 2010
13:34:56.789

C or c

Currency

Decimal Places

C = 1,234.00
C4 = 1,234.0000

C = 1,234.56
C4 = 1,234.560

d or dd

Day

d/M
dd/M

3/12
03/12

D or d

Decimal

Minimum Digits

D = 1234
D6 = 001234

n/a

ddd or dddd

Day Name

ddd d/M
dddd d/M

Fri 3/12
Friday 3/12

E or e

Exponential

Decimal Places

e = 1.230000e+002
E3 = 1.234E+002

e = 1.234567e+002
E3 = 1.235E+002

f or F

Tenths

s.f

56.7

Decimal Places

F = 1234.00
F4 = 1234.0000

F = 1234.57
F4 = 1234.5670

ff or FF

Hundredths

s.ff

56.78

General

Significant Digits

G = 1234
G2 = 12E+03

G = 1234.567
G4 = 1235

fff or FFF

Milliseconds

s.fff

56.789

N or n

Number

Desired Decimal
Places

N = 1,234.00
N4 = 1,234.0000

N = 1,234.57
N4 = 1,234.5670

ffff or FFFF

Ten Thousandths

s.ffff

56.7890

P or p

Percent

Decimal Places

P = 123,400.00 %
P0 = 123,400 %

P = 123,456.70 %
P0 = 123,457 %

fffff or FFFFF

Hundred Thousandths

s.fffff

56.78900

R or r

Round-Trip

n/a

n/a

R = 1234.567

ffffff or FFFFFF

Millionths

s.ffffff

56.78900

Number of Digits

x = 4d2
X4 = 04D2

n/a

g or gg

Era

d/M/yyyy g

3/12/2010 A.D.

h or hh

Hour (12-Hour Clock)

h:mm
hh:mm

1:34
01:34

H or HH

Hour (24-Hour Clock)

H:mm
HH:mm

13:34
13:34

Time Zone

HH:mmK

13:34+00:00
13:34
13:34

F or f
G or g

X or x

Fixed Point

Hexadecimal

Custom Numeric Format Strings


Specifier

Name

Example Values

Example Formats

Results

Zero Placeholder

1234
1234.567

00000
0

01234
1235

m or mm

Minute

H:m
H:mm

Digit Placeholder

1234
1234.567

#####
#

1234
1235

M or MM

Month

d/M
dd/MM

3/12
03/12

Decimal Point

1234
1234.567

0.00
0.00

1234.00
1234.57

MMM or MMMM

Month Name

d MMM
d MMMM

3 Dec
3 December

Group Separator

1234
1234.567

#,#.00
000,000.00

1,234.00
001,234.57

s or ss

Second

m:s
m:ss

34:56
34:56

Number Scaling

1234567
1234567

#,,
#,#,.00

1
1,234.57

t ot tt

AM/PM

h:mm t
h:mm tt

1:34 P
1:34 PM

Percentage
Placeholder

0.5
0.875

#%
#.00%

50%
87.50%

Year (One Digit Minimum)

MMM y

Dec 10

Per Mille
Placeholder

0.5
0.875

#%
#.00%

500
875.00%

yy

Year (Two Digit Minimum)

MMM yy

Dec 10

E0 or e0

Exponential

1234.567
0.01234

E0
e4

1E+003
1.2340e-002

yyy

Year (Three Digit Minimum)

MMM yyy

Dec 2010

E+0 or e+0

Exponential with
Sign

1234.567
0.01234

#.##E+00
0.00e+000

1.23E+03
12.3e-002

yyyy

Year (Four Digit Minimum)

MMM yyyy

Dec 2010

E-0 or e-0

Exponential with
Negative Sign

1234.567
0.01234

#.##E-00
0.00e-000

1.23E03
12.32e-002

yyyyy

Year (Five Digits)

MMM yyyyy

Dec 02010

Escape Character

1234
1234

\#0,0
\\0,0

#1,234
\1,234

z or zz

UTC Offset in Hours

HH:mmz
HH:mmzz

13:34+0
13:34+00

or

Literal String

1234
1234

0,0 0,0
0,0 0,0

1,234 0,0
1,234 0,0

zzz

UTC Offset in Hours and


Minutes

HH:mmzzz

13:34+00:00

Section Separator
(Two Sections)

1234
-1234

0,0;(0,0)
0,0;(0,0)

1,234
(1,234)

Local Time Separator

HH:mm

13:34

Section Separator
(Three Sections)

-1234
0

0,0;(0,0);0,0;(0,0);-

(1,234)
-

Local Date Separator

dd/MM/yyyy

03/12/2010

Escape Character

HH\H

13H

or

Literal String

ETA HH:mm
ETA HH:mm

ETA 13:34
ETA 13:34

Single Character Custom


Format

%d

Standard DateTime Format Strings

Format

Name

UK

US

Short Date

31/12/2010

12/31/2010

Long Date

31 December 2010

Friday, December 31, 2010

Full Date, Short


Time

31 December 2010 13:00

Friday, December 31, 2010


1:00 PM

Format

Name

Example

Full Date, Long


Time

31 December 2010 13:00:00

Friday, December 31, 2010


1:00:00 PM

Digits Only

0123456789abcdef0123456789abcdef

General Date,
Short Time

13/12/2010:13:00

12/31/2010 1:00 PM

Hyphenated

01234567-89ab-cdef-0123-456789abcdef

General Date,
Long Time

13/12/2010:13:00:00

12/31/2010 1:00:00 PM

Braces

{01234567-89ab-cdef-0123-456789abcdef}

M or m

Month / Day

31 December

December 31

Parentheses

(01234567-89ab-cdef-0123-456789abcdef)

O or o

Round-Trip

2010-1231T13:00:00.0000000

2010-1231T13:00:00.0000000

Hexadecimal

{0x01234567,0x89ab,0xcdef,{0x01,0x23,0x45,0x67,0x89,0xa
b,0xcd,0xef}}

R or r

RFC1123

Fri, 31 Dec 2010 13:00:00


GMT

Fri, 31 Dec 2010 13:00:00


GMT

Sortable

2010-12-31T13:00:00

2010-12-31T13:00:00

Short Time

13:00

1:00 PM

Format

Name

Height | Width

Long Time

13:00:00

1:00:00PM

G or G

String

Height, Width

Universal
Sortable

2010-12-31 13:00:00Z

2010-12-31 20:00:00Z

F or f

String Even Without


Flags Attribute

Height, Width

Universal Full
Date / Time

31 December 2010 13:00:00

Friday, December 31, 2010


8:00:00 PM

D or d

Numeric Value

Y or y

Year / Month

December 2010

December, 2010

X or x

Hexadedimal

00000003

http://www.blackwasp.co.uk

Globally Unique Identifier (GUID) Format Strings

Enumeration Format Strings

Sample Enum

[Flags]
enum Dimensions
{
Depth,
Height,
Width
}

You might also like