This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
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 : IFormatProviderpublic ref class DateTimeFormatInfo sealed : ICloneable, IFormatProviderpublic ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider, System::Runtime::Serialization::ISerializablepublic sealed class DateTimeFormatInfo : IFormatProviderpublic 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, IFormatProvidertype DateTimeFormatInfo = class interface IFormatProvidertype 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 IFormatProviderPublic NotInheritable Class DateTimeFormatInfoImplements IFormatProviderPublic NotInheritable Class DateTimeFormatInfoImplements ICloneable, IFormatProviderPublic NotInheritable Class DateTimeFormatInfoImplements ICloneable, IFormatProvider, ISerializableThe 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, 2012Imports 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, 2012For more information about this API, seeSupplemental API remarks for DateTimeFormatInfo.
| Name | Description |
|---|---|
| DateTimeFormatInfo() | Initializes a new writable instance of theDateTimeFormatInfo class that is culture-independent (invariant). |
| Name | Description |
|---|---|
| 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. |
| Name | Description |
|---|---|
| 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) |
| Name | Description |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) | Populates a SerializationInfo with the data needed to serialize the target object. |
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?