Tuesday, March 30, 2010

.NET Standard DateTime Format Strings


.NET Standard DateTime Format Strings

Specifier

Name

Description

d

Short date pattern

Represents a custom DateTime format string defined by the current ShortDatePattern
property.

D

Long date pattern

Represents a custom DateTime format string defined by the current LongDatePattern
property.

f

Full date/time pattern (short time)

Represents a combination of the long date (D) and short time (t) patterns, separated
by a space.

F

Full date/time pattern (long time)

Represents a custom DateTime format string defined by the current FullDateTimePattern
property.

g

General date/time pattern (short time)

Represents a combination of the short date (d) and short time (t) patterns, separated
by a space.

G

General date/time pattern (long time)

Represents a combination of the short date (d) and long time (T) patterns, separated
by a space.

M or m

Month day pattern

Represents a custom DateTime format string defined by the current MonthDayPattern
property.

o

Round-trip date/time pattern

Represents a custom DateTime format string using a pattern that preserves time zone
information. The pattern is designed to round-trip DateTime formats, including the
Kind property, in text. Then the formatted string can be parsed back using Parse
or ParseExact with the correct Kind property value. Equivalent custom format string
is "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK".

R or r

RFC1123 pattern

Represents a custom DateTime format string defined by the current RFC1123Pattern
property. The pattern is a defined standard and the property is readonly. Equivalent
custom format string is "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'". Does not convert
DateTimes to UTC.

s

Sortable date/time pattern; ISO 8601

Represents a custom DateTime format string defined by the current SortableDateTimePattern
property. This pattern is a defined standard and the property is read-only. Equivalent
custom format string is "yyyy'-'MM'-'dd'T'HH':'mm':'ss".

t

Short time pattern

Represents a custom DateTime format string defined by the current ShortTimePattern
property. For example, the custom format string for the invariant culture is "HH:mm".

T

Long time pattern

Represents a custom DateTime format string defined by the current LongTimePattern
property. For example, the custom format string for the invariant culture is "HH:mm:ss".

u

Universal sortable date/time pattern

Represents a custom DateTime format string defined by the current UniversalSortableDateTimePattern
property. Equivalent custom format string is "yyyy'-'MM'-'dd HH':'mm':'ss'Z'". Does
not convert DateTimes to UTC.

U

Universal sortable date/time pattern

Represents a custom DateTime format string defined by the current FullDateTimePattern
property. This pattern is the same as the full date/long time (F) pattern. However,
formatting operates on the Coordinated Universal Time (UTC) that is equivalent to
the DateTime object being formatted.

Y or y

Year month pattern

Represents a custom DateTime format string defined by the current YearMonthPattern
property. For example, the custom format string for the invariant culture is "yyyy
MMMM".

Any other single character

(Unknown specifier)

An unknown specifier throws a runtime format exception.

No comments:

Post a Comment