Net Standard Datetime Format Strings

ADVERTISEMENT

.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
Represents a combination of the long date (D) and short time (t) patterns, separated by a space.
(short time)
F
Full date/time pattern
Represents a custom DateTime format string defined by the current FullDateTimePattern property.
(long time)
g
General date/time
Represents a combination of the short date (d) and short time (t) patterns, separated by a space.
pattern (short time)
G
General date/time
Represents a combination of the short date (d) and long time (T) patterns, separated by a space.
pattern (long time)
M or m
Month day pattern
Represents a custom DateTime format string defined by the current MonthDayPattern property.
o
Round-trip date/time
Represents a custom DateTime format string using a pattern that preserves time zone information. The pattern is designed to round-trip DateTime
pattern
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 read-
only. Equivalent custom format string is "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'". Does not convert DateTimes to UTC.
s
Sortable date/time
Represents a custom DateTime format string defined by the current SortableDateTimePattern property.
pattern; ISO 8601
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
Represents a custom DateTime format string defined by the current UniversalSortableDateTimePattern property.
date/time pattern
Equivalent custom format string is "yyyy'-'MM'-'dd HH':'mm':'ss'Z'". Does not convert DateTimes to UTC.
U
Universal sortable
Represents a custom DateTime format string defined by the current FullDateTimePattern property. This pattern is the same as the full date/long time (F)
date/time pattern
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
(Unknown specifier)
An unknown specifier throws a runtime format exception.
character
More .NET Cheat Sheets available at

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 6