Standard DateTime format string

xiaoxiao2021-03-06  90

Standard DateTime Format string contains a format specifier in the table below. If there is no such format specifier in the table below, it will raise an exception. If the format string is longer than a single character, the format string is interpreted as a custom format string.

Note that the output string produced by these format specifiers is affected by the settings in the Area Options control panel. Different output strings are generated in the regional setting or date and time setting of the computer.

The time and date separator displayed by the format string are made from current regional

DateTimeFormat

Attribute association

Dateseparator

with

TimeseParetor

Character definition. However, if

InvariantCulture

The characters associated with DateSeparator and TimeSeparetor characters are not changed with current regional changes.

The following table describes the standard format specifiers used to format the DateTime object.

Format Description Name Description D Short date mode Display is associated with the current thread

DatetimeFormatinfo.shortdatePattern

The mode defined by the property or the mode defined by the specified format. D Long Date Mode Display is associated with the current thread

DateTimeFormatinfo.longdatePattern

The mode defined by the property or the mode defined by the specified format. T short time mode display is associated with the current thread

DateTimeFormatinfo.shortTimePattern

The mode defined by the property or the mode defined by the specified format. T length mode display is associated with the current thread

DateTimeFormatinfo.longTimePattern

The mode defined by the property or the mode defined by the specified format. f Complete Date / Time Mode (short time) Displays a combination of long-term and short time modes, separated by spaces. F Complete Date / Time Mode (Long Time) Display is associated with the current thread

DateTimeFormatinfo.FullDateTimePattern

The mode defined by the property or the mode defined by the specified format. g Regular Date / Time Mode (short time) Displays a combination of short-term and short time mode, separated by spaces. G Regular Date / Time Mode (Long Time) Displays a combination of short date and long mode, separated by spaces. M or M Moon mode display is associated with current threads

DateTimeFormatinfo.monthdaypattern

The mode defined by the property or the mode defined by the specified format. R or RRFC1123 mode display is associated with the current thread

DateTimeFormatinfo.rfc1123pattern

The mode defined by the property or the mode defined by the specified format. This is the standard defined, and attribute is read-only; therefore, it is always the same regardless of what the area or the format provider is provided. The property references the CultureInfo.invariantCulture property and follows the custom mode "DDD MMM YYYY HH: MM: SS G / MT". Note that "M" in "GMT" requires an escaping, so it is not interpreted. Format does not modify the value of DateTime, so you must adjust the value to GMT before formatting. S can be sorted by date / time mode; in line with ISO 8601 display is associated with current threads

DateTimeFormatinfo.sortableDateTimePattern

The mode defined by the property or the mode defined by the specified format. The property references the CultureInfo.invariantCulture property, the format complies with custom mode "YYYY-MM-DDTHH: MM: SS". u GMSLO date / time mode display is associated with the current thread

DateTimeFormatinfo.UniversalsalsalSortableDateTimePattern

The mode defined by the property or the mode defined by the specified format. Because it is a defined standard, and attribute is read-only, the mode is always the same regardless of the regional or format provider. Format Follow the custom mode "YYYY-MM-DD HH: MM: SSZ". Do not perform time zone conversion when formatting date and time; so, transform local dates and time before using the format specifier to generic time. U GMSD date / time pattern Display DateTimeFormatinfo.fulDatetimePattern associated with the current thread

The mode defined by the property or the mode defined by the specified format. Please note that the display time is a versatile time, not local time. Y or Y Yun Moon Mode Display is associated with the current thread

DateTimeFormatinfo.YearMonthpattern

The mode defined by the property or the mode defined by the specified format. Any other single character unknown specifier

The following example illustrates how the standard format string is used with the DateTime object.

[Visual Basic]

DIM DT as datetime = datetime.now

DIM DFI As datetimeformatinfo = new datetimeformatinfo ()

DIM CI As CultureInfo = New CultureInfo ("DE-DE")

'Make Up A New Custom DateTime Pattern, for Demonstration.

DFI.MONTHDAYPATTERN = "MM-MMMM, DDD-DDDD"

'Use the datetimeformat from the culture associated

'with the current thread.

Console.writeline (DT.ToString ("D"))

Console.Writeline (DT.ToString ("M"))

'Use the datetimeformat from the specific Culture Pass.

Console.Writeline (DT.ToString ("D", CI))

'Use the settings from the datetimeformatinfo object passed.

Console.writeline (DT.ToString ("M", DFI))

'Reset the current thread to a different culture.

Thread.currentthread.currentculture = New CultureInfo ("fr-be")

Console.writeline (DT.ToString ("D"))

[C #]

DateTime DT = datetime.now;

DateTimeFormatinfo DFI = New DateTimeFormatinfo ();

CultureInfo Ci = New CultureInfo ("DE-DE");

// make Up A New Custom DateTime Pattern, for DemonStration.

DFI.MONTHDAYPATTERN = "MM-MMMM, DDD-DDDD";

// use the datetimeformat from the culture associated

// with the current thread.

Console.WriteLine (DT.ToString ("D"));

Console.writeline (DT.TOString ("M")); // Use the datetimeformat from the specific Culture Pass.

Console.WriteLine (DT.ToString ("D", CI));

// use the settings from the datetimeformatinfo object passed.

Console.WriteLine (DT.ToString ("M", DFI));

// reset the current thread to a different culture.

Thread.currentthread.currentculture = New CultureInfo ("fr-be");

Console.WriteLine (DT.ToString ("D"));

See

Format Overview | Format Type | Date and Time Format String | Standard DateTime Format String Output Example

Send an opinion about this topic

© 2001-2002 Microsoft Corporation. all rights reserved.

转载请注明原文地址:https://www.9cbs.com/read-106500.html

New Post(0)