public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
Object
DateTimeFormatInfoThis type implements ICloneable and IFormatProvider.
mscorlib
BCL
Defines culture-specific formats and patterns for DateTime values.
DateTime values are formatted by the System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods according to standard or custom patterns stored in the properties of a DateTimeFormatInfo instance. The standard patterns can be accessed and modified through the associated DateTimeFormatInfo properties. [Note: The format patterns and properties of a read-only DateTimeFormatInfo instance cannot be changed. To determine whether a DateTimeFormatInfo instance is read-only, use the System.Globalization.DateTimeFormatInfo.IsReadOnly property.]
Date and time format patterns are specified using strings called format specifiers. A string is interpreted as standard format specifier if it contains exactly one standard format specifier character. If the string contains a single character and that character is not one of the standard format specifiers, an exception is thrown. If the string contains two or more characters, even if the extra characters are white spaces, the string is interpreted as a custom format specifier. Format specifiers and format patterns are case-sensitive; for example, 'g' and 'G' represent different patterns.
The following table shows the standard format specifiers and the associated format pattern defined for the invariant culture. The exact pattern produced by a format specifier is influenced by culture-specific date and/or time settings on the current system; computers with different date and time settings might display different patterns. The asterisk at the end of a format pattern indicates that the preceding character can be repeated without changing the meaning of the pattern. For example, the pattern "HH*" indicates that the strings "HH", "HHH", "HHHH", and "HHHHH" produce the same result when used with System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods.
The following table lists custom format specifiers that can be combined to construct custom patterns. If the custom pattern contains white space characters, characters enclosed in single or double quotation marks, or characters not defined in the following table, these characters are considered literals and are included in the output string unchanged. [Note: See the String class for the list of white space characters.]
Format Specifier Format Pattern d MM/dd/yyyy D dddd*, dd MMMM* yyyy f dddd*, dd MMMM* yyyy HH*:mm* F dddd*, dd MMMM* yyyy HH*:mm*:ss* g MM/dd/yyyy HH*:mm* G MM/dd/yyyy HH*:mm*:ss* m, M MMMM* dd t HH*:mm* T HH*:mm*:ss* U dddd*, dd MMMM* yyyy HH*:mm*:ss* y, Y yyyy MMMM*
Format Pattern Description d The day of the month as a value in the range 1-31, inclusive. Single-digit days do not have a leading zero. dd The day of the month as a value in the range 1-31, inclusive. Single-digit days have a leading zero. ddd The abbreviated name of the day of the week, as defined in System.Globalization.DateTimeFormatInfo.AbbreviatedDayNames . dddd* The full name of the day of the week, as defined in System.Globalization.DateTimeFormatInfo.DayNames . M The numeric month as a value in the range 1-12, inclusive. Single-digit months do not have a leading zero. MM The numeric month as a value in the range 1-12, inclusive. Single-digit months have a leading zero. MMM The abbreviated name of the month, as defined in System.Globalization.DateTimeFormatInfo.AbbreviatedMonthNames . MMMM* The full name of the month, as defined in System.Globalization.DateTimeFormatInfo.MonthNames . y The year without the century (two-digit). If the value is less than 10, the year is displayed with no leading zero. yy The year without the century (two-digit). If the year without the century is less than 10, the year is displayed with a leading zero. yyyy The year including the century in four digits. g* The name of a period or era (such as "A.D." or "B.C."). This pattern is ignored if the date to be formatted does not have an associated period or era string. h The hour within a 12-hour range as a value in the range 1-12, inclusive. Single-digit hours do not have a leading zero. [Note: The value represents whole hours passed since either midnight (12) or noon (12). To distinguish between values occurring before and after noon, include the "t" or "tt*" custom format specifier.]
hh* The hour within a 12-hour range as a value in the range 1-12, inclusive. Single-digit hours have a leading zero. [Note: The value represents whole hours passed since either midnight (12) or noon (12). To distinguish between values occurring before and after noon, include the "t" or "tt*" custom format specifier.]
H The hour as a value in the range 0-23, inclusive. Single-digit hours do not have a leading zero. [Note: The value represents whole hours passed since midnight.]
HH* The hour as a value in the range 0 and 23, inclusive. Single-digit hours have a leading zero. [Note: The value represents whole hours passed since midnight.]
m The minute as a value in the range 0-59, inclusive. Single-digit minutes do not have a leading zero. [Note: The value represents whole minutes passed since the last hour.]
mm* The minute as a value in the range 0-59, inclusive. Single-digit minutes have a leading zero. [Note: The value represents whole minutes passed since the last hour.]
s The second as a value in the range 0-59, inclusive. Single-digit seconds do not have a leading zero. [Note: The value represents whole seconds passed since the last minute.]
ss* The second as a value in the range 0-59, inclusive. Single-digit seconds have a leading zero. [Note: The value represents whole seconds passed since the last minute.]
f Displays fractional seconds represented in one digit. ff Displays fractional seconds represented in two digits. fff Displays fractional seconds represented in three digits. ffff Displays fractional seconds represented in four digits. fffff Displays fractional seconds represented in five digits. ffffff Displays fractional seconds represented in six digits. fffffff Displays fractional seconds represented in seven digits. t The first character of the AM/PM designator defined in the DateTimeFormatInfo property System.Globalization.DateTimeFormatInfo.AMDesignator or System.Globalization.DateTimeFormatInfo.PMDesignator. [Note: If the total number of hours passed since midnight is less than 12, the A.M. designator is used; otherwise the P.M. designator is used.]
tt* The AM/PM designator defined in the DateTimeFormatInfo property System.Globalization.DateTimeFormatInfo.AMDesignator or System.Globalization.DateTimeFormatInfo.PMDesignator. [Note: If the total number of hours passed since midnight is less than 12, the A.M. designator is used; otherwise the P.M. designator is used.]
z The time zone offset (hour only) from the universal time coordinate (UTC) time (Greenwich Mean Time) as a value in the range -12 to +13, inclusive. Single-digit hours do not have a leading zero. [Note: The value always includes a leading sign (zero is '+0'), indicating hours ahead of UTC time (+) or hours behind UTC time (-). The offset takes Daylight Savings Time into account.]
zz The time zone offset (hour only) from the UTC time (Greenwich Mean Time) as a value in the range -12 to +13, inclusive. Single-digit hours have a leading zero. [Note: The value always includes a leading sign (zero is '+0'), indicating hours ahead of UTC time (+) or hours behind UTC time (-). The offset takes Daylight Savings Time into account.]
zzz* The full time zone offset (hour and minutes) from the UTC time (Greenwich Mean Time) as a value in the range -12:00 to +13:00, inclusive. Single-digit hours and minutes have leading zeros. [Note: The value always includes a leading sign (zero is '+0'), indicating hours ahead of UTC time (+) or hours behind UTC time (-). The offset takes Daylight Savings Time into account.]
: The invariant culture time separator defined in System.Globalization.DateTimeFormatInfo.TimeSeparator . / The invariant culture date separator defined in the System.Globalization.DateTimeFormatInfo.DateSeparator . %c c represents a single custom format character. Produces the custom format pattern associated with the format character c. The %c specifier provides a mechanism for specifying a single custom format character and having it recognized as a custom specifier. This format is intended for characters that define both a custom and a standard format. Note that a format string containing exactly one such character will be interpreted as a standard format specifier unless prefaced with the %. [Note: For example, for the invariant culture, "%d" produces the single or double digit date, while "d" produces the date in "MM/dd/yyyy" format. Without the %, a format string containing one character would have to include leading or trailing white space to be interpreted as a custom specifier because custom formats are required to have two or more characters.]
\c c represents any character predefined as part of a format specifier. Prevents the character from being interpreted as a format specifier (the character is treated as a literal). [Note: In programming languages where the backslash ('\') character is used to specify control sequences such as newline (\n), the backslash character is required to be specified twice. For example, in C#, "\d" is coded as "\\d".]
'xx' or "xx" xx represents a string of characters of any length. The characters are treated as literals.
System.Globalization Namespace
DateTimeFormatInfo Constructors
DateTimeFormatInfo Constructor
DateTimeFormatInfo Methods
DateTimeFormatInfo.Clone Method
DateTimeFormatInfo.GetAbbreviatedMonthName Method
DateTimeFormatInfo.GetEra Method
DateTimeFormatInfo.GetEraName Method
DateTimeFormatInfo.GetFormat Method
DateTimeFormatInfo.GetMonthName Method
DateTimeFormatInfo.ReadOnly Method
DateTimeFormatInfo Properties
DateTimeFormatInfo.AMDesignator Property
DateTimeFormatInfo.AbbreviatedDayNames Property
DateTimeFormatInfo.AbbreviatedMonthNames Property
DateTimeFormatInfo.CurrentInfo Property
DateTimeFormatInfo.DateSeparator Property
DateTimeFormatInfo.DayNames Property
DateTimeFormatInfo.FullDateTimePattern Property
DateTimeFormatInfo.InvariantInfo Property
DateTimeFormatInfo.IsReadOnly Property
DateTimeFormatInfo.LongDatePattern Property
DateTimeFormatInfo.LongTimePattern Property
DateTimeFormatInfo.MonthDayPattern Property
DateTimeFormatInfo.MonthNames Property
DateTimeFormatInfo.PMDesignator Property
DateTimeFormatInfo.ShortDatePattern Property
DateTimeFormatInfo.ShortTimePattern Property
DateTimeFormatInfo.TimeSeparator Property
DateTimeFormatInfo.YearMonthPattern Property
public DateTimeFormatInfo();
Constructs and initializes a new instance of the DateTimeFormatInfo class that is culture-independent (invariant).
The new instance of DateTimeFormatInfo is not read-only, and its properties can be modified with user-defined patterns.
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public object Clone();
Creates a copy of the current instance.
A new DateTimeFormatInfo instance with property values equal to the property values of the original DateTimeFormatInfo instance.
The System.Globalization.DateTimeFormatInfo.Clone method creates a new instance of the same type as the current instance, and then copies the contents of each of the current instance's non-static fields.The new instance is not read-only, and its properties can be modified with user-defined patterns.
[Note: This method is implemented to support the ICloneable interface.]
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string GetAbbreviatedMonthName(int month);
Gets the abbreviated name of the specified month based on the culture of the current thread.
- month
- A Int32 from 1 through 13 representing the month name to retrieve.
A String containing the abbreviated name of the month represented by month. For cultures with 12-month calendars, the empty string is returned as the name of the 13th month.
Exception Type Condition ArgumentOutOfRangeException month is less than 1 or greater than 13.
For the default (culture-invariant) DateTimeFormatInfo instance, this method returns one of the following strings:
[Note: This method supports calendars with 13 months.]
month Return Value 1 "Jan" 2 "Feb" 3 "Mar" 4 "Apr" 5 "May" 6 "Jun" 7 "Jul" 8 "Aug" 9 "Sep" 10 "Oct" 11 "Nov" 12 "Dec" 13 ""
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public int GetEra(string eraName);
Gets a Int32 representing the specified era.
- eraName
- A String containing the name of the era.
A Int32 representing the era. If eraName is invalid, returns -1.
Exception Type Condition ArgumentNullException eraName is a null reference.
The value specified for eraName is case-insensitive.[Note: An era name is a culturally specific name for a period of time marked by distinctive characters or reckoned from a fixed point or event. For example "A.D." and "B.C." are two eras of the Gregorian calendar.]
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string GetEraName(int era);
Gets the String containing the name of the specified era.
- era
- A Int32 representing the era.
A String containing the name of the era.
Exception Type Condition ArgumentOutOfRangeException era does not represent a valid era in calendar for the current thread.
[Note: An era name is a culturally specific name for a period of time marked by distinctive characters or reckoned from a fixed point or event. For example "A.D." and "B.C." are two eras of the Gregorian calendar.]
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public object GetFormat(Type formatType);
Returns an object of the specified type that provides DateTime formatting services.
- formatType
- The Type of the formatting object to be returned.
The current instance, if formatType is of type DateTimeFormatInfo; otherwise, a null reference.
[Note: This method is implemented to support the IFormatProvider interface.]
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string GetMonthName(int month);
Gets the full name of the specified month based on the culture of the current thread.
- month
- A Int32 from 1 through 13 representing the month name to retrieve.
A String containing the full name of the month represented by month. For cultures with 12-month calendars the empty string is returned as the name of the 13th month.
Exception Type Condition ArgumentOutOfRangeException month is less than 1 or greater than 13.
For the default (culture invariant) DateTimeFormatInfo instance, this method returns one of the following strings:
[Note: This method supports calendars with 13 months.]
month Return Value 1 "January" 2 "February" 3 "March" 4 "April" 5 "May" 6 "June" 7 "July" 8 "August" 9 "September" 10 "October" 11 "November" 12 "December" 13 ""
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi);
Returns a read-only copy of the specified instance of DateTimeFormatInfo .
- dtfi
- The DateTimeFormatInfo to copy.
A read-only instance of DateTimeFormatInfo that is a copy of dtfi.
Exception Type Condition ArgumentNullException dtfi is a null reference.
[Note: Use a read-only DateTimeFormatInfo copy to prevent modifications to the specified instance.]
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string AMDesignator { get; set; }
Gets or sets the String culture-specific designator for hours that are "ante meridiem" (before noon).
The String designator for hours that are before noon.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The property value of the culture invariant System.Globalization.DateTimeFormatInfo.AMDesignator returns the String "AM".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string[] AbbreviatedDayNames { get; set; }
Gets or sets a one-dimensional array of type String containing the culture-specific abbreviated names of the days of the week.
A one-dimensional array of type String containing the culture-specific abbreviated names of the days of the week.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. ArgumentException The value specified for a set operation is not an array with exactly 7 elements. InvalidOperationException The current instance is read-only and a set operation was attempted.
The array specified in a set operation is required to be one-dimensional and have exactly seven elements. The first element of the array is the abbreviated day name for Sunday, and the last element is the name for Saturday.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.AbbreviatedDayNames is a String array that contains "Sun", "Mon", "Tue", "Wed", "Thu", "Fri" and "Sat".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string[] AbbreviatedMonthNames { get; set; }
Gets or sets a one-dimensional array of type String containing the culture-specific abbreviated names of the months.
A one-dimensional array of type String containing the abbreviated names of the months. For cultures with 12-month calendars the 13th element of the array is an empty string.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. ArgumentException The value specified for a set operation is not an array with exactly 13 elements. InvalidOperationException The current instance is read-only and a set operation was attempted.
The Array specified in a set operation is required to be one-dimensional and have exactly 13 elements.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.AbbreviatedMonthNames is a String array that contains "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" and "".
[Note: The array returned by this property has 13 elements to support calendars with 13 months.]
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public static DateTimeFormatInfo CurrentInfo { get; }
Gets a read-only DateTimeFormatInfo instance that formats values based on the current culture.
A read-only DateTimeFormatInfo instance based on the culture of the current thread.
This property is read-only.
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string DateSeparator { get; set; }
Gets or sets the culture-specific String to use to separate the year, month, and day components of a date.
The String to use to separate the year, month and day components of a date.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The property value of the culture invariant System.Globalization.DateTimeFormatInfo.DateSeparator is "/".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string[] DayNames { get; set; }
Gets or sets a one-dimensional array of type String containing the culture-specific full names of the days of the week.
A one-dimensional array of type String containing the full names of the days of the week.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. ArgumentException The value specified for a set operation is not an array with exactly 7 elements. InvalidOperationException The current instance is read-only and a set operation was attempted.
The array specified in a set operation is required to be one-dimensional and have exactly seven elements. The first element of the array is the abbreviated day name for Sunday, and the last element is the name for Saturday.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.DayNames is a String array that contains "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" and "Saturday".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string FullDateTimePattern { get; set; }
Gets or sets the format pattern for a long date and long time value.
A String containing the format pattern for a long date and long time value.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods associate the format pattern returned by this property with the 'F' format character.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.FullDateTimePattern is "dddd, dd MMMM yyyy HH:mm:ss".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public static DateTimeFormatInfo InvariantInfo { get; }
Gets a culture invariant instance of DateTimeFormatInfo that is read-only.
A read-only DateTimeFormatInfo instance.
This property is read-only.
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public bool IsReadOnly { get; }
Gets a Boolean value indicating whether the current DateTimeFormatInfo instance is read-only.
true
if the DateTimeFormatInfo is read-only; otherwise,false
.
This property is read-only.
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string LongDatePattern { get; set; }
Gets or sets the format pattern for a long date value.
A String containing the format pattern for a long date value.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods associate the format pattern returned by this property with the 'D' format character.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.LongDatePattern is "dddd, dd MMMM yyyy".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string LongTimePattern { get; set; }
Gets or sets the format pattern for a long time value.
A String containing the format pattern for a long time value.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods associate the format pattern returned by this property with the 'T' format character.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.LongTimePattern is "HH:mm:ss".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string MonthDayPattern { get; set; }
Gets or sets the format pattern for a month and day value.
A String containing the format pattern for a month and day value.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods associate the format pattern returned by this property with the 'm' and 'M' format characters.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.MonthDayPattern is "MMMM dd".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string[] MonthNames { get; set; }
Gets or sets a one-dimensional array of type String containing the culture-specific full names of the months.
A one-dimensional array of type String containing the full names of the months. For cultures with 12-month calendars the 13th element of the array is an empty string.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. ArgumentException The value specified for a set operation is not an array with exactly 13 elements. InvalidOperationException The current instance is read-only and a set operation was attempted.
The array specified in a set operation is required be one-dimensional and have exactly 13 elements.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.MonthNames is a String array that contains "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" and "".
[Note: The array returned by this property has 13 elements to support calendars with 13 months.]
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string PMDesignator { get; set; }
Gets or sets the culture-specific String designator for hours that are "post meridiem" (after noon).
The String designator for hours that are after noon.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The property value of the culture invariant System.Globalization.DateTimeFormatInfo.PMDesignator is "PM".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string ShortDatePattern { get; set; }
Gets or sets the format pattern for a short date value.
A String containing the format pattern for a short date value.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods associate the format pattern returned by this property with the 'd' format character.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.ShortDatePattern is "MM/dd/yyyy".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string ShortTimePattern { get; set; }
Gets or sets the format pattern for a short time value.
A String containing the format pattern for a short time value.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods associate the format pattern returned by this property with the 't' format character.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.ShortTimePattern is "HH:mm".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string TimeSeparator { get; set; }
Gets or sets the culture-specific String to use to separate the components of time values (hour, minutes, seconds).
The String to use to separate the components of time; that is, the hour, the minutes and the seconds.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The property value of the culture invariant System.Globalization.DateTimeFormatInfo.TimeSeparator is ":".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace
public string YearMonthPattern { get; set; }
Gets or sets the format pattern for a year and month value.
The format pattern for a year and month value.
Exception Type Condition ArgumentNullException The value specified for a set operation is a null reference. InvalidOperationException The current instance is read-only and a set operation was attempted.
The System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider) and System.DateTime.ToString methods associate the format pattern returned by this property with the 'y' and 'Y' format character.The property value of the culture invariant System.Globalization.DateTimeFormatInfo.YearMonthPattern is "yyyy MMMM".
System.Globalization.DateTimeFormatInfo Class, System.Globalization Namespace