DateTimeFormatinfo

xiaoxiao2021-03-05  22

.NET Framework class library

DateTimeFormatinfo class [C #]

See

DateTimeFormatinfo Member | System.globalization Namespace | DateTime | Calendar | CultureInfo | TabINDEX = "0" Keywords = "CPConFormattingOverView"> Format Overview | DateTimeFormatinfo Member (Visual J # Syntax) | C Hosting Extension Programming

Claim

Name Space: System.globalization

Platform: Windows 98, Windows NT 4.0, Windows Me, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Series, .NET Framework Lite - Windows CE .NET

Accessure: Mscorlib (in Mscorlib.dll)

Language

C # C JScriptvisual Basic is displayed

Define how to set the DateTime value according to regional settings and displays these values.

For a list of all members of this type, see the DateTimeFormatinfo member.

System.Object System.globalization.DatetimeFormatinfo

[Visual Basic]

Notinheritable Public Class DateTimeFormatinfo

Implements Icloneable, IFORMATPROVIDER

[C #]

[Serializable]

Public Sealed Class DateTimeFormatinfo: Icloneable,

IFORMATPROVIDER

[C ]

[Serializable]

Public __gc __sealed class datetimeformatinfo: Public iCloneable,

IFORMATPROVIDER

[Jscript]

public

Serializable

Class DateTimeFormatinfo Implements Icloneable,

IFORMATPROVIDER

Thread security

All public static (Visual Basic) members are safe for multithreading operations. But not to ensure that any instance member is thread safe.

Note

Such a variety of information, such as date mode, time mode, and AM / PM indicator.

To create a DateTimeFormatinfo for a particular area, create CultureInfo for this area and retrieve the CultureInfo.dateTimeFormat property. To create DateTimeFormatinfo for the regionality of the current thread, use the CurrentInfo property. To create a DateTimeFormatinfo for a fixed area, use the InvariantIntinfo property to read version, or use the DateTimeFormatinfo constructor to be able to handle. It is impossible to create DateTimeFormatinfo for non-specific regionality.

The user can select the value associated with the current regionality of Windows by "Regional and Language Options" (or "Regional Options" or "Region Settings" in the Control Panel. For example, the user may choose to display the date in another format, or choose a currency other than the regional default setting. If the CultureInfo.Useuseroverride property is set to True, you will also retrieve the CultureInfo.dateTimeFormat instance, the property of the CultureInfo.Numberformat instance, and the CultureInfo.TextInfo instance from the user setting. If the user settings associated with CultureInfo is incompatible (for example, the selected calendar is not one of OptionalCalendars), the method results and attribute values ​​are undefined. Use the standard or custom mode stored in the properties of the DateTimeFormatinfo to set the format of the DateTime value.

You can replace standard modes with custom mode with custom mode with custom mode with custom modest properties. To determine if the DateTimeFormatinfo is writable, use the isReadOnly property.

The following table lists the standard format characters of each standard mode and setting the associated DateTimeFormatInfo property that can modify the standard mode. The format characters are case sensitive; for example, "G" and "G" representatives are slightly different.

Format Character Association Properties / Description DshortdatePattern DlongDatePattern F Complete Date and Time (Long Date and Short Time) FfuldateTimePattern (Long Date and Long) G General (short date and short time) G General (short date and long) M, MMONTHDAYPATTERN R RRFC1123PATTERN S uses local time sortabledatetimepattern (based on ISO 8601) TswostTern UuniversalsalsalSortableDateTimePattern UUniversalsalSortableDateTimePattern Using the Format U using generic times using generic times full date and time (long dates and long) Y, YYEARMONTHPATTERN

The following table lists the modes that can be merged to construct a custom mode. These modes are case sensitive; for example, identify "mm" but do not identify "mm". If the custom mode contains a blank character or a character enclosed in a single quotes, the output string will also contain these characters. Unfained part of the format mode or the character that is not defined as a formatted character is replicated according to its original.

Format mode Description Di Month Day. There is no preamble zero. One day in the DD month. One-digit date has a preamble zero. The abbreviated name of a day in the DDD week is defined in AbbreviatedDayNames. The full name of a day in the DDDD week is defined in daysNames. M month numbers. There is no preamble zero one month. MM month figures. One month has a preamble zero. MMM's abbreviation name is defined in AbbreviatedMonthnames. The full name of the MMMM month is defined in MonthNames. Y does not include the year of the era. If the year does not include a year less than 10, the year does not have a leading zero. YY does not contain the year of the era. If the year does not include a year less than 10, the year with the leading zero is displayed. YYYY includes the four-digit year of the era. GG period or era. This mode is ignored if the date you want to set the format does not have an associated period or an era string. H12 hours of hours. One of the few hours does not have a preamble zero. HH12 hours of hours. One-digit hour has a preamble zero. H24 hours of hours. One of the few hours does not have a preamble zero. HH24 hours of hours. One-digit hour has a preamble zero. m minutes. One bit of minutes has no preamble zero. MM minutes. One of the number of minutes has a preamble zero. s second. One-digit seconds no preamble zero. SS seconds. A number of seconds has a preamble zero. The decimal accuracy of F seconds is one. The remaining numbers are truncated. FF seconds of decimal precision is two. The remaining numbers are truncated. The decimal accuracy of the FFF seconds is three. The remaining numbers are truncated. FFFF seconds of decimal precision is four. The remaining numbers are truncated. The decimal accuracy of FFFFF is five. The remaining numbers are truncated. The decimal accuracy of fffffff seconds is six. The remaining numbers are truncated. The decimal accuracy of fffffff is seven. The remaining numbers are truncated. T in the AM / PM indicator defined in the AMDESIGNATOR or PMDesignator (if present). TT defines the AM / PM indicator (if present) in AmDesignator or PMDesignator. The z time zone offset (" " or "-" is only hone with an hour). One of the few hours does not have a preamble zero. For example, the Pacific standard time is "-8". The zz time zone offset (" " or "-" is only homed to hours). One-digit hour has a preamble zero. For example, the Pacific Standard Time is "-08". The zzz complete time zone offset (" " or "-" has hours and minutes). One of the few hours and the number of minutes have a preamble zero. For example, the Pacific standard time is "-08: 00". : The default time separator defined in the TimeSeparator. / The default date separator defined in the DateSeparator. % c where C is format mode (if used separately). If the format mode merges with the primary character or other format mode, the "%" character can be omitted. / c where C is any character. Amazer display character. To display a backslash character, use "//". Only the format mode listed in the second table can be used to create custom modes; the standard format characters listed in the first table cannot be used to create custom modes. The length of the custom mode is at least two characters; for example,

DateTime.toString ("D") Returns a DateTime value; "D" is the standard short date mode. DateTime.toString ("% D") returns a certain day in the moon; "% D" is a custom mode. DateTime.toString ("D") Returns a certain day in the moon behind it; "D" is a custom mode.

DateTimeFormatinfo or NumberFormatinfo or NumberFormatinfo can only be created for fixed area or specific region, without creating non-specific regions. For more information on fixed region, specific regionality, and non-specific regions, see the CultureInfo class.

This class implements the iCloneable interface to enable replication of the DateTimeFormatinfo object. It also implements IFORMATPROVIDER to format information for applications. Example

[Visual Basic, C #, C ] The following code example uses the format character to output EN-US region different format mode. This example will also display the attribute value associated with the format character.

[Visual Basic]

Imports system

Imports system.globalization

Imports Microsoft.visualBasic

Public Class Samplesdtfi

Public Shared Sub Main ()

'Creates and Initializes a datetimeformatinfo associated with the en-us culture.

Dim mydtfi as datetimeformatinfo = New CultureInfo ("en-us", false) .datetimeformat

'Creates a datetime with the Gregorian Date January 3, 2002 (Year = 2002, Month = 1, day = 3).

'The Gregorian Calendar is The Default Calendar for the En-US Culture.

DIM MyDT As New DateTime (2002, 1, 3)

'Displays the format pattern associated with each format character.

Console.WriteLine ("Format En-US Example")

Console.writeline ("char value of associated printy, if any")

Console.writeLine ()

Console.WriteLine ("D {0}", Mydt.Tostring ("D"))))

Console.writeline ("{0} {1}", mydtfi.shortdatepattern, "(shortdatepattern)")

Console.writeLine ()

Console.WriteLine ("D {0}", Mydt.Tostring ("D"))))

Console.writeline ("{0} {1}", mydtfi.longdatepattern, "(longdatepattern)")

Console.writeLine ()

Console.WriteLine ("f {0}", mydt.tostring ("f")))

Console.writeLine ()

Console.WriteLine ("f {0}", mydt.tostring ("f")))

Console.writeline ("{0} {1}", mydtfi.fuldatetimepattern, "(fulldatetimepattern)")

Console.writeLine ()

Console.WriteLine ("g {0}", mydt.tostring ("g")))

Console.writeLine ()

Console.writeline ("g {0}", mydt.tostring ("g")) Console.writeline ()

Console.writeline ("M {0}", mydt.tostring ("m")))

Console.writeLine ("{0} {1}", mydtfi.monthdaypattern, "(MONTHDAYPATTERN)")

Console.writeLine ()

Console.writeline ("M {0}", mydt.tostring ("m")))

Console.writeLine ("{0} {1}", mydtfi.monthdaypattern, "(MONTHDAYPATTERN)")

Console.writeLine ()

Console.writeline ("r {0}", mydt.tostring ("r")))

Console.writeline ("{0} {1}", mydtfi.rfc1123pattern, "(RFC1123Pattern)")

Console.writeLine ()

Console.writeline ("r {0}", mydt.tostring ("r")))

Console.writeline ("{0} {1}", mydtfi.rfc1123pattern, "(RFC1123Pattern)")

Console.writeLine ()

Console.WriteLine ("s {0}", mydt.tostring ("s")))

Console.writeline ("{0} {1}", mydtfi.sortabledatetimepattern, "" ")")

Console.writeLine ()

Console.writeline ("T {0}", mydt.tostring ("t")))

Console.writeLine ("{0} {1}", mydtfi.shorttimepattern, "(ShortTimePattern)")

Console.writeLine ()

Console.writeline ("T {0}", mydt.tostring ("t")))

Console.writeline ("{0} {1}", mydtfi.longtimepattern, "(longtimepattern)")

Console.writeLine ()

Console.WriteLine ("u {0}", mydt.tostring ("u"))

Console.writeline ("{0} {1}", mydtfi.Universalsaln, "(universalsalSortableDateTimePattern)")

Console.writeLine ()

Console.WriteLine ("u {0}", mydt.tostring ("u"))

Console.writeLine ()

Console.writeline ("Y {0}", mydt.tostring ("y")) Console.writeLine ("{0} {1}", mydtfi.yearmonthpattern, "" ")")

Console.writeLine ()

Console.writeline ("y {0}", mydt.tostring ("y")))

Console.writeline ("{0} {1}", mydtfi.yearmonthpattern, "" "") ")

End Sub 'Main

End Class' SamplesDTFI

'This Code Produces The Following Output.

'

'Format en-US Example

'Char value of associated printy, if any

'

'D 1/3/2002

'M / d / yyyy (shortdatepattern)

'

'D Thursday, January 03, 2002

'DDDD, MMMM DD, YYYY (longdatepattern)

'

'f Thursday, January 03, 2002 12:00 AM

'

'F Thursday, January 03, 2002 12:00:00 AM

'DDDD, MMMM DD, YYYY H: MM: SS TT (FulldateTimePattern)

'

'g 1/3/2002 12:00 am

'

'G 1/3/2002 12:00:00 AM

'

'm january 03

'Mmmm DD (MonthdayPattern)

'

'M january 03

'Mmmm DD (MonthdayPattern)

'

'R THU, 03 Jan 2002 00:00:00 GMT

'DDD, DD MMM YYYY HH': 'mm': 'SS' GMT '(RFC1123Pattern)

'

'R THU, 03 Jan 2002 00:00:00 GMT

'DDD, DD MMM YYYY HH': 'mm': 'SS' GMT '(RFC1123Pattern)

'

'S 2002-01-03T00: 00: 00

'YYYY' - 'mm' - 'DD't'HH': 'mm': 'ss (sortabledatetimepattern)

'

'T 12:00 AM

'h: mm Tt (ShortTimePattern)

'

'T 12:00:00 AM

'h: mm: SS TT (longtimepattern)

'

'u 2002-01-03 00: 00:00Z

'YYYY' - 'mm' - 'DD HH': 'mm': 'ss'z' (universalsalSortableDateTimePattern) '

'U thursday, January 03, 2002 8:00:00 AM

'

'Y January, 2002

'Mmmm, yyyy (YearmonThpattern)

'

'Y January, 2002

'Mmmm, yyyy (YearmonThpattern)

'

[C #]

Using system;

USING SYSTEM.GLOBALIZATION;

Public class samplesdtfi {

Public static void main () {

// Creates and Initializes a datetimeformatinfo associated with the en-us culture.

DateTimeFormatinfo mydtfi = New CultureInfo ("EN-US", FALSE) .DATETIMEFORMAT;

// Creates a datetime with the Gregorian Date January 3, 2002 (YEAR = 2002, Month = 1, day = 3).

// The Gregorian Calendar is The Default Calendar for the En-US Culture.

DateTime mydt = new datetime (2002, 1, 3);

// Displays the format pattern associated with each format character CHARACTER.

Console.writeline ("Format En-US Example");

Console.writeline ("char value of associated printy, if any / n");

Console.writeline ("D {0}", MyDt.Tostring ("D"));

Console.writeline ("{0} {1} / n", mydtfi.shortdatepattern, "" (shortdatepattern) ");

Console.writeline ("D {0}", MyDt.Tostring ("D"));

Console.writeline ("{0} {1} / n", mydtfi.longdatepattern, "(longdatepattern)");

Console.WriteLine ("f {0} / n", mydt.tostring ("f");

Console.WriteLine ("f {0}", mydt.tostring ("f");

Console.writeLine ("{0} {1} / n", mydtfi.ffiskatetimepattern, "(fulldatetimepattern))

Console.writeline ("g {0} / n", mydt.tostring ("g"));

Console.writeline ("g {0} / n", mydt.tostring ("g"));

Console.Writeline ("M {0}", mydt.tostring ("m");

Console.writeLine ("{0} {1} / n", mydtfi.monthdaypattern, "(MONTHDAYPATTERN)")

Console.Writeline ("M {0}", mydt.tostring ("m");

Console.writeLine ("{0} {1} / n", mydtfi.monthdaypattern, "(MONTHDAYPATTERN)")

Console.writeline ("r {0}", mydt.tostring ("r");

Console.writeline ("{0} {1} / n", mydtfi.rfc1123pattern, "(RFC1123Pattern)")

Console.writeline ("r {0}", mydt.tostring ("r");

Console.writeline ("{0} {1} / n", mydtfi.rfc1123pattern, "(RFC1123Pattern)")

Console.WriteLine ("s {0}", mydt.tostring ("s"));

Console.writeline ("{0} {1} / n", mydtfi.sortabledatetimepattern, "" "")

Console.WriteLine ("T {0}", MyDt.toString ("T"));

Console.writeline ("{0} {1} / n", mydtfi.shorttimepattern, "(ShortTimePattern)")

Console.WriteLine ("T {0}", MyDt.toString ("T"));

Console.writeline ("{0} {1} / n", mydtfi.longtimepattern, "(longtimepattern)")

Console.writeline ("u {0}", mydt.tostring ("u"));

Console.writeline ("{0} {1} / n", mydtfi.UniversalsalSortableDatetimePattern, "(universalsalSortableDateTimePattern)")

Console.writeline ("u {0} / n", mydt.tostring ("u");

Console.WriteLine ("y {0}", mydt.toString ("y"));

Console.writeline ("{0} {1} / n", mydtfi.yearmonthpattern, "" "" "y {0}", mydt.tostring ("y"));

Console.writeline ("{0} {1} / n", mydtfi.yearmonthpattern, "" "" ")

}

}

/ *

This Code Produces The Following Output.

Format en-US Example

Char value of associated printy, if any

D 1/3/2002

M / D / YYYY (shortdatepattern)

D Thursday, January 03, 2002

DDDD, MMMM DD, YYYY (longdatepattern)

F Thursday, January 03, 2002 12:00 AM

F Thursday, January 03, 2002 12:00:00 AM

DDDD, MMMM DD, YYYY H: MM: SS TT (FulldateTimePattern)

G 1/3/2002 12:00 am

G 1/3/2002 12:00:00 AM

M january 03

MMMM DD (MonthdayPattern)

M january 03

MMMM DD (MonthdayPattern)

R Thu, 03 Jan 2002 00:00:00 GMT

DDD, DD MMM YYYY HH ':' mm ':' s 'GMT' (RFC1123Pattern)

R Thu, 03 Jan 2002 00:00:00 GMT

DDD, DD MMM YYYY HH ':' mm ':' s 'GMT' (RFC1123Pattern)

S 2002-01-03T00: 00: 00

YYYY '-' mm '-' DD't'HH ':' mm ':' SS (SortableDateTimePattern)

T 12:00 AM

H: mm TT (ShortTimePattern)

T 12:00:00 AM

H: mm: SS TT (longTimePattern)

u 2002-01-03 00: 00: 00Z

YYYY '-' MM '-' DD HH ':' mm ':' SS'Z '(UniversalsalsAn "

U Thursday, January 03, 2002 8:00:00 AM

Y January, 2002

MMMM, YYARMONTHPATTERN)

Y January, 2002

MMMM, YYARMONTHPATTERN)

* /

[C ]

#using

Using Namespace System;

Using Namespace System :: globalization;

int main ()

{

// Creates and Initializes a datetimeformatinfo associated with the en-us culture.

CultureInfo * MyCI = New CultureInfo (s "en-us", false);

DateTimeFormatinfo * mydtfi = myci -> DateTimeFormat;

// Creates a datetime with the Gregorian Date January 3, 2002 (YEAR = 2002, Month = 1, day = 3).

// The Gregorian Calendar is The Default Calendar for the En-US Culture.

DateTime mydt = datetime (2002, 1, 3);

// Displays the format pattern associated with each format character CHARACTER.

Console :: WriteLine (S "format en-us example");

Console :: WriteLine (s "char value of associated proty, if any / n");

Console :: WriteLine (S "D {0}", mydt.tostring (s "d"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> shortdatepattern, s ")");

Console :: WriteLine (S "D {0}", mydt.tostring (s "d"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> longdatepattern, s "(longdatepattern)")

Console :: WriteLine (s "f {0} / n", mydt.tostring (s "f"));

Console :: WriteLine (S "f {0}", mydt.tostring (s "f"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> fulldatetimepattern, s ");

Console :: WriteLine (s "g {0} / n", mydt.tostring (s "g"));

Console :: WriteLine (s "g {0} / n", mydt.tostring (s "g"));

Console :: WriteLine (s "m {0}", mydt.tostring (s "m"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> monthdaypattern, s ");

Console :: WriteLine (s "m {0}", mydt.tostring (s "m"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> monthdaypattern, s ");

Console :: WriteLine (s "r {0}", mydt.tostring (s "r"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> rfc1223pattern, s "); console :: write (s" r {0} ", mydt.tostring (s" r "));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> rfc123pattern, s "(rfc1123pattern)")

Console :: WriteLine (s "s {0}", mydt.tostring (s "));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> sortabledatetimepattern, s ")")

Console :: WriteLine (s "t {0}", mydt.tostring (s "t"));

Console :: WriteLine (S "{0} {1} / n", mydtfi -> shorttimepattern, s ");

Console :: WriteLine (s "t {0}", mydt.tostring (s "t"));

Console :: WriteLine (S "{0} {1} / n", mydtfi -> longtimepattern, s "(longtimepattern)")

Console :: WriteLine (s "u {0}", mydt.tostring (s "u"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> universalsalSortableDateTimePattern, S ")")

Console :: WriteLine (s "u {0} / n", mydt.tostring (s "u"));

Console :: WriteLine (s "y {0}", mydt.tostring (s "y"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> yearmonthpattern, s ");

Console :: WriteLine (s "y {0}", mydt.tostring (s "y"));

Console :: WriteLine (s "{0} {1} / n", mydtfi -> yearmonthpattern, s ");

}

/ *

This Code Produces The Following Output.

Format en-US Example

Char value of associated printy, if any

D 1/3/2002

M / D / YYYY (shortdatepattern)

D Thursday, January 03, 2002

DDDD, MMMM DD, YYYY (longdatepattern)

F Thursday, January 03, 2002 12:00 AM

F Thursday, January 03, 2002 12:00:00 AMDDDD, MMMM DD, YYYY H: MM: SS TT (FulldateTimePattern)

G 1/3/2002 12:00 am

G 1/3/2002 12:00:00 AM

M january 03

MMMM DD (MonthdayPattern)

M january 03

MMMM DD (MonthdayPattern)

R Thu, 03 Jan 2002 00:00:00 GMT

DDD, DD MMM YYYY HH ':' mm ':' s 'GMT' (RFC1123Pattern)

R Thu, 03 Jan 2002 00:00:00 GMT

DDD, DD MMM YYYY HH ':' mm ':' s 'GMT' (RFC1123Pattern)

S 2002-01-03T00: 00: 00

YYYY '-' mm '-' DD't'HH ':' mm ':' SS (SortableDateTimePattern)

T 12:00 AM

H: mm TT (ShortTimePattern)

T 12:00:00 AM

H: mm: SS TT (longTimePattern)

u 2002-01-03 00: 00: 00Z

YYYY '-' MM '-' DD HH ':' mm ':' SS'Z '(UniversalsalsAn "

U Thursday, January 03, 2002 8:00:00 AM

Y January, 2002

MMMM, YYARMONTHPATTERN)

Y January, 2002

MMMM, YYARMONTHPATTERN)

* /

[JScript] There is no example available for JScript. To view Visual Basic, C # or C examples, click the "Language Filter" button in the upper left corner.

Claim

Name Space: System.globalization

Platform: Windows 98, Windows NT 4.0, Windows Me, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Series, .NET Framework Lite - Windows CE .NET

Accessure: Mscorlib (in Mscorlib.dll)

See

DateTimeFormatinfo Member | System.globalization Namespace | DateTime | Calendar | CultureInfo | TabINDEX = "0" Keywords = "CPConFormattingOverView"> Format Overview

| DateTimeFormatinfo Members (Visual J # Syntax) | C Hosting Extension Programming

Send an opinion about this topic

TabINDEX = "0" keywords = "Copybeta_nonfidential"> © 2001-2002 Microsoft Corporation. all rights reserved.

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

New Post(0)