In some circumstances, the normal format string serves as a effortless abbreviation for a lengthier customized format string that is invariant. Four typical format strings drop into this classification: “O” (or “o”, “R” (or “r”, “s”, and “u”. These strings correspond to custom structure strings described by the invariant society.
They generate string representations of day and time values that are supposed to be identical throughout cultures. The subsequent desk offers details on these 4 common date and time format strings. Standard structure string Outlined by DateTimeFormatInfo. InvariantInfo residence Personalized format string “O” or “o” None yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss’. ‘fffffffK “R” or “r” RFC1123Pattern ddd, dd MMM yyyy HH’:’mm’:’ss ‘GMT’ “s” SortableDateTimePattern yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss “u” UniversalSortableDateTimePattern yyyy’-‘MM’-‘dd HH’:’mm’:’ss’Z’Standard format strings can also be used in parsing functions with the DateTime. ParseExact or DateTimeOffset. ParseExact techniques, which require an input string to specifically conform to a certain pattern for the parse procedure to be successful. Quite a few regular format strings map to multiple custom made format strings, so a day and time benefit fling dating meaning can be represented in a selection of formats and the parse operation will nonetheless realize success.
You can identify the personalized format string or strings that correspond to a typical format string by contacting the DateTimeFormatInfo. GetAllDateTimePatterns(Char) method. The following case in point displays the custom format strings that map to the “d” (limited date pattern) normal structure string. The pursuing sections describe the conventional structure specifiers for DateTime and DateTimeOffset values. Date formats. This group involves the adhering to formats:The brief date “d” structure specifier. The “d” normal structure specifier signifies a custom made day and time format string that is outlined by a precise culture’s DateTimeFormatInfo. ShortDatePattern residence. For illustration, the custom made format string that is returned by the ShortDatePattern house of the invariant culture is “MM/dd/yyyy”. The pursuing table lists the DateTimeFormatInfo item properties that command the formatting of the returned string. Property Description ShortDatePattern Defines the all round format of the result string.
DateSeparator Defines the string that separates the year, month, and working day factors of a date. The pursuing case in point takes advantage of the “d” structure specifier to screen a date and time value. The very long date “D” format specifier. The “D” typical format specifier represents a customized date and time format string that is described by the present-day DateTimeFormatInfo. LongDatePattern house. For case in point, the personalized format string for the invariant society is “dddd, dd MMMM yyyy”. The following table lists the qualities of the DateTimeFormatInfo item that handle the formatting of the returned string. Property Description LongDatePattern Defines the general structure of the outcome string. DayNames Defines the localized working day names that can surface in the final result string. MonthNames Defines the localized thirty day period names that can surface in the consequence string. The pursuing example uses the “D” format specifier to screen a date and time value. Date and time formats. This team features the pursuing formats:The full date small time “f” format specifier. The “f” normal format specifier represents a mixture of the extended date “D” and shorter time “t” designs, separated by a area.