Movatterモバイル変換


[0]ホーム

URL:


Skip to main contentSkip to in-page navigation

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

DateTimeFormatInfo Class

Definition

Namespace:
System.Globalization
Assemblies:
mscorlib.dll, System.Globalization.dll
Assemblies:
netstandard.dll, System.Runtime.dll
Assembly:
System.Globalization.dll
Assembly:
System.Runtime.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
DateTimeFormatInfo.cs
Source:
DateTimeFormatInfo.cs
Source:
DateTimeFormatInfo.cs
Source:
DateTimeFormatInfo.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Provides culture-specific information about the format of date and time values.

public ref class DateTimeFormatInfo sealed : IFormatProvider
public ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider
public ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider, System::Runtime::Serialization::ISerializable
public sealed class DateTimeFormatInfo : IFormatProvider
public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
[System.Serializable]public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider, System.Runtime.Serialization.ISerializable
[System.Serializable][System.Runtime.InteropServices.ComVisible(true)]public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
type DateTimeFormatInfo = class    interface IFormatProvider
type DateTimeFormatInfo = class    interface ICloneable    interface IFormatProvider
[<System.Serializable>]type DateTimeFormatInfo = class    interface ICloneable    interface IFormatProvider    interface ISerializable
[<System.Serializable>][<System.Runtime.InteropServices.ComVisible(true)>]type DateTimeFormatInfo = class    interface ICloneable    interface IFormatProvider
Public NotInheritable Class DateTimeFormatInfoImplements IFormatProvider
Public NotInheritable Class DateTimeFormatInfoImplements ICloneable, IFormatProvider
Public NotInheritable Class DateTimeFormatInfoImplements ICloneable, IFormatProvider, ISerializable
Inheritance
DateTimeFormatInfo
Attributes
Implements

Examples

The following example uses reflection to get the properties of theDateTimeFormatInfo object for the English (United States) culture. It displays the value of those properties that contain custom format strings and uses those strings to display formatted dates.

using System;using System.Globalization;using System.Reflection;public class Example{   public static void Main()   {      // Get the properties of an en-US DateTimeFormatInfo object.      DateTimeFormatInfo dtfi = CultureInfo.GetCultureInfo("en-US").DateTimeFormat;      Type typ = dtfi.GetType();      PropertyInfo[] props = typ.GetProperties();      DateTime value = new DateTime(2012, 5, 28, 11, 35, 0);      foreach (var prop in props) {         // Is this a format pattern-related property?         if (prop.Name.Contains("Pattern")) {            string fmt = prop.GetValue(dtfi, null).ToString();            Console.WriteLine("{0,-33} {1} \n{2,-37}Example: {3}\n",                              prop.Name + ":", fmt, "",                              value.ToString(fmt));         }      }   }}// The example displays the following output://    FullDateTimePattern:              dddd, MMMM dd, yyyy h:mm:ss tt//                                         Example: Monday, May 28, 2012 11:35:00 AM////    LongDatePattern:                  dddd, MMMM dd, yyyy//                                         Example: Monday, May 28, 2012////    LongTimePattern:                  h:mm:ss tt//                                         Example: 11:35:00 AM////    MonthDayPattern:                  MMMM dd//                                         Example: May 28////    RFC1123Pattern:                   ddd, dd MMM yyyy HH':'mm':'ss 'GMT'//                                         Example: Mon, 28 May 2012 11:35:00 GMT////    ShortDatePattern:                 M/d/yyyy//                                         Example: 5/28/2012////    ShortTimePattern:                 h:mm tt//                                         Example: 11:35 AM////    SortableDateTimePattern:          yyyy'-'MM'-'dd'T'HH':'mm':'ss//                                         Example: 2012-05-28T11:35:00////    UniversalSortableDateTimePattern: yyyy'-'MM'-'dd HH':'mm':'ss'Z'//                                         Example: 2012-05-28 11:35:00Z////    YearMonthPattern:                 MMMM, yyyy//                                         Example: May, 2012
Imports System.GlobalizationImports System.ReflectionModule Example   Public Sub Main()      ' Get the properties of an en-US DateTimeFormatInfo object.      Dim dtfi As DateTimeFormatInfo = CultureInfo.GetCultureInfo("en-US").DateTimeFormat      Dim typ As Type = dtfi.GetType()      Dim props() As PropertyInfo = typ.GetProperties()      Dim value As Date = #05/28/2012 11:35AM#             For Each prop In props         ' Is this a format pattern-related property?         If prop.Name.Contains("Pattern") Then            Dim fmt As String = CStr(prop.GetValue(dtfi, Nothing))            Console.WriteLine("{0,-33} {1} {2}{3,-37}Example: {4}",                               prop.Name + ":", fmt, vbCrLf, "",                              value.ToString(fmt))             Console.WriteLine()         End If      Next   End SubEnd Module' The example displays the following output:'    FullDateTimePattern:              dddd, MMMM dd, yyyy h:mm:ss tt'                                         Example: Monday, May 28, 2012 11:35:00 AM'    '    LongDatePattern:                  dddd, MMMM dd, yyyy'                                         Example: Monday, May 28, 2012'    '    LongTimePattern:                  h:mm:ss tt'                                         Example: 11:35:00 AM'    '    MonthDayPattern:                  MMMM dd'                                         Example: May 28'    '    RFC1123Pattern:                   ddd, dd MMM yyyy HH':'mm':'ss 'GMT''                                         Example: Mon, 28 May 2012 11:35:00 GMT'    '    ShortDatePattern:                 M/d/yyyy'                                         Example: 5/28/2012'    '    ShortTimePattern:                 h:mm tt'                                         Example: 11:35 AM'    '    SortableDateTimePattern:          yyyy'-'MM'-'dd'T'HH':'mm':'ss'                                         Example: 2012-05-28T11:35:00'    '    UniversalSortableDateTimePattern: yyyy'-'MM'-'dd HH':'mm':'ss'Z''                                         Example: 2012-05-28 11:35:00Z'    '    YearMonthPattern:                 MMMM, yyyy'                                         Example: May, 2012

Remarks

For more information about this API, seeSupplemental API remarks for DateTimeFormatInfo.

Constructors

NameDescription
DateTimeFormatInfo()

Initializes a new writable instance of theDateTimeFormatInfo class that is culture-independent (invariant).

Properties

NameDescription
AbbreviatedDayNames

Gets or sets a one-dimensional array of typeString containing the culture-specific abbreviated names of the days of the week.

AbbreviatedMonthGenitiveNames

Gets or sets a string array of abbreviated month names associated with the currentDateTimeFormatInfo object.

AbbreviatedMonthNames

Gets or sets a one-dimensional string array that contains the culture-specific abbreviated names of the months.

AMDesignator

Gets or sets the string designator for hours that are "ante meridiem" (before noon).

Calendar

Gets or sets the calendar to use for the current culture.

CalendarWeekRule

Gets or sets a value that specifies which rule is used to determine the first calendar week of the year.

CurrentInfo

Gets a read-onlyDateTimeFormatInfo object that formats values based on the current culture.

DateSeparator

Gets or sets the string that separates the components of a date, that is, the year, month, and day.

DayNames

Gets or sets a one-dimensional string array that contains the culture-specific full names of the days of the week.

FirstDayOfWeek

Gets or sets the first day of the week.

FullDateTimePattern

Gets or sets the custom format string for a long date and long time value.

InvariantInfo

Gets the default read-onlyDateTimeFormatInfo object that is culture-independent (invariant).

IsReadOnly

Gets a value indicating whether theDateTimeFormatInfo object is read-only.

LongDatePattern

Gets or sets the custom format string for a long date value.

LongTimePattern

Gets or sets the custom format string for a long time value.

MonthDayPattern

Gets or sets the custom format string for a month and day value.

MonthGenitiveNames

Gets or sets a string array of month names associated with the currentDateTimeFormatInfo object.

MonthNames

Gets or sets a one-dimensional array of typeString containing the culture-specific full names of the months.

NativeCalendarName

Gets the native name of the calendar associated with the currentDateTimeFormatInfo object.

PMDesignator

Gets or sets the string designator for hours that are "post meridiem" (after noon).

RFC1123Pattern

Gets the custom format string for a time value that is based on the Internet Engineering Task Force (IETF) Request for Comments (RFC) 1123 specification.

ShortDatePattern

Gets or sets the custom format string for a short date value.

ShortestDayNames

Gets or sets a string array of the shortest abbreviated day names associated with the currentDateTimeFormatInfo object.

ShortTimePattern

Gets or sets the custom format string for a short time value.

SortableDateTimePattern

Gets the custom format string for a sortable date and time value.

TimeSeparator

Gets or sets the string that separates the components of time, that is, the hour, minutes, and seconds.

UniversalSortableDateTimePattern

Gets the custom format string for a universal, sortable date and time string, as defined by ISO 8601.

YearMonthPattern

Gets or sets the custom format string for a year and month value.

Methods

NameDescription
Clone()

Creates a shallow copy of theDateTimeFormatInfo.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited fromObject)
GetAbbreviatedDayName(DayOfWeek)

Returns the culture-specific abbreviated name of the specified day of the week based on the culture associated with the currentDateTimeFormatInfo object.

GetAbbreviatedEraName(Int32)

Returns the string containing the abbreviated name of the specified era, if an abbreviation exists.

GetAbbreviatedMonthName(Int32)

Returns the culture-specific abbreviated name of the specified month based on the culture associated with the currentDateTimeFormatInfo object.

GetAllDateTimePatterns()

Returns all the standard patterns in which date and time values can be formatted.

GetAllDateTimePatterns(Char)

Returns all the patterns in which date and time values can be formatted using the specified standard format string.

GetDayName(DayOfWeek)

Returns the culture-specific full name of the specified day of the week based on the culture associated with the currentDateTimeFormatInfo object.

GetEra(String)

Returns the integer representing the specified era.

GetEraName(Int32)

Returns the string containing the name of the specified era.

GetFormat(Type)

Returns an object of the specified type that provides a date and time formatting service.

GetHashCode()

Serves as the default hash function.

(Inherited fromObject)
GetInstance(IFormatProvider)

Returns theDateTimeFormatInfo object associated with the specifiedIFormatProvider.

GetMonthName(Int32)

Returns the culture-specific full name of the specified month based on the culture associated with the currentDateTimeFormatInfo object.

GetShortestDayName(DayOfWeek)

Obtains the shortest abbreviated day name for a specified day of the week associated with the currentDateTimeFormatInfo object.

GetType()

Gets theType of the current instance.

(Inherited fromObject)
MemberwiseClone()

Creates a shallow copy of the currentObject.

(Inherited fromObject)
ReadOnly(DateTimeFormatInfo)

Returns a read-onlyDateTimeFormatInfo wrapper.

SetAllDateTimePatterns(String[], Char)

Sets the custom date and time format strings that correspond to a specified standard format string.

ToString()

Returns a string that represents the current object.

(Inherited fromObject)

Explicit Interface Implementations

NameDescription
ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data needed to serialize the target object.

Applies to

See also

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?