[Serializable] |
To create a DateTimeFormatInfo for a specific culture, create a CultureInfo for that culture and retrieve the CultureInfo.DateTimeFormat property. To create a DateTimeFormatInfo for the culture of the current thread, use the DateTimeFormatInfo.CurrentInfo property. To create a DateTimeFormatInfo for the invariant culture, use the DateTimeFormatInfo.InvariantInfo property for a read-only version, or use the DateTimeFormatInfo constructor for a writable version. It is not possible to create a DateTimeFormatInfo for a neutral culture.
The user might choose to override some of the values associated with the current culture of Windows through Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the CultureInfo.UseUserOverride property is set to true, the properties of the CultureInfo.DateTimeFormat instance, the CultureInfo.NumberFormat instance, and the CultureInfo.TextInfo instance are also retrieved from the user settings. If the user settings are incompatible with the culture associated with the CultureInfo (for example, if the selected calendar is not one of the CultureInfo.OptionalCalendars), the results of the methods and the values of the properties are undefined.
DateTime values are formatted using standard or custom patterns stored in the properties of a DateTimeFormatInfo.
The standard patterns can be replaced with custom patterns by setting the associated properties of a writable DateTimeFormatInfo. To determine if a DateTimeFormatInfo is writable, use the DateTimeFormatInfo.IsReadOnly property.
The following table lists the standard format characters for each standard pattern and the associated DateTimeFormatInfo property that can be set to modify the standard pattern. The format characters are case-sensitive; for example, 'g' and 'G' represent slightly different patterns.
Format Character | Associated Property / Description | Example Format Pattern (en-US) |
---|---|---|
d | DateTimeFormatInfo.ShortDatePattern | MM/dd/yyyy |
D | DateTimeFormatInfo.LongDatePattern | dddd, dd MMMM yyyy |
f | Full date and time (long date and short time) | dddd, dd MMMM yyyy HH:mm |
F | DateTimeFormatInfo.FullDateTimePattern (long date and long time) | dddd, dd MMMM yyyy HH:mm:ss |
g | General (short date and short time) | MM/dd/yyyy HH:mm |
G | General (short date and long time) | MM/dd/yyyy HH:mm:ss |
m, M | DateTimeFormatInfo.MonthDayPattern | MMMM dd |
r, R | DateTimeFormatInfo.RFC1123Pattern | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' |
s | DateTimeFormatInfo.SortableDateTimePattern (based on ISO 8601) using local time | yyyy'-'MM'-'dd'T'HH':'mm':'ss |
t | DateTimeFormatInfo.ShortTimePattern | HH:mm |
T | DateTimeFormatInfo.LongTimePattern | HH:mm:ss |
u | DateTimeFormatInfo.UniversalSortableDateTimePattern using universal time | yyyy'-'MM'-'dd HH':'mm':'ss'Z' |
U | Full date and time (long date and long time) using universal time | dddd, dd MMMM yyyy HH:mm:ss |
y, Y | DateTimeFormatInfo.YearMonthPattern | yyyy MMMM |
The following table lists the patterns that can be combined to construct custom patterns. The patterns are case-sensitive; for example, "MM" is recognized, but "mm" is not. If the custom pattern contains white-space characters or characters enclosed in single quotation marks, the output string will also contain those characters. Characters not defined as part of a format pattern or as format characters are reproduced literally.
Format Pattern | Description |
---|---|
d | The day of the month. Single-digit days will not have a leading zero. |
dd | The day of the month. Single-digit days will have a leading zero. |
ddd | The abbreviated name of the day of the week, as defined in DateTimeFormatInfo.AbbreviatedDayNames . |
dddd | The full name of the day of the week, as defined in DateTimeFormatInfo.DayNames . |
M | The numeric month. Single-digit months will not have a leading zero. |
MM | The numeric month. Single-digit months will have a leading zero. |
MMM | The abbreviated name of the month, as defined in DateTimeFormatInfo.AbbreviatedMonthNames . |
MMMM | The full name of the month, as defined in DateTimeFormatInfo.MonthNames . |
y | The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero. |
yy | The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero. |
yyyy | The year in four digits, including the century. |
gg | The period or era. This pattern is ignored if the date to be formatted does not have an associated period or era string. |
h | The hour in a 12-hour clock. Single-digit hours will not have a leading zero. |
hh | The hour in a 12-hour clock. Single-digit hours will have a leading zero. |
H | The hour in a 24-hour clock. Single-digit hours will not have a leading zero. |
HH | The hour in a 24-hour clock. Single-digit hours will have a leading zero. |
m | The minute. Single-digit minutes will not have a leading zero. |
mm | The minute. Single-digit minutes will have a leading zero. |
s | The second. Single-digit seconds will not have a leading zero. |
ss | The second. Single-digit seconds will have a leading zero. |
f | The fraction of a second in single-digit precision. The remaining digits are truncated. |
ff | The fraction of a second in double-digit precision. The remaining digits are truncated. |
fff | The fraction of a second in three-digit precision. The remaining digits are truncated. |
ffff | The fraction of a second in four-digit precision. The remaining digits are truncated. |
fffff | The fraction of a second in five-digit precision. The remaining digits are truncated. |
ffffff | The fraction of a second in six-digit precision. The remaining digits are truncated. |
fffffff | The fraction of a second in seven-digit precision. The remaining digits are truncated. |
t | The first character in the AM/PM designator defined in DateTimeFormatInfo.AMDesignator or DateTimeFormatInfo.PMDesignator . |
tt | The AM/PM designator defined in DateTimeFormatInfo.AMDesignator or DateTimeFormatInfo.PMDesignator . |
z | The time zone offset ("+" or "-" followed by the hour only). Single-digit hours will not have a leading zero. For example, Pacific Standard Time is "-8". |
zz | The time zone offset ("+" or "-" followed by the hour only). Single-digit hours will have a leading zero. For example, Pacific Standard Time is "-08". |
zzz | The full time zone offset ("+" or "-" followed by the hour and minutes). Single-digit hours and minutes will have leading zeros. For example, Pacific Standard Time is "-08:00". |
: | The default time separator defined in DateTimeFormatInfo.TimeSeparator . |
/ | The default date separator defined in DateTimeFormatInfo.DateSeparator . |
% | Where is a format pattern if used alone. The "%" character can be omitted if the format pattern is combined with literal characters or other format patterns. |
\ | Where is any character. Displays the character literally. To display the backslash character, use "\\". |
Only format patterns listed in the second table above can be used to create custom patterns; standard format characters listed in the first table cannot be used to create custom patterns. Custom patterns are at least two characters long; for example,
A DateTimeFormatInfo or a NumberFormatInfo can be created only for the invariant culture or for specific cultures, not for neutral cultures. For more information about the invariant culture, specific cultures, and neutral cultures, see the CultureInfo class.
This class implements the ICloneable interface to enable duplication of DateTimeFormatInfo objects. It also implements IFormatProvider to supply formatting information to applications.
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. Initializes a new writable instance of the DateTimeFormatInfo class that is culture-independent (invariant). |
AbbreviatedDayNames | Read-write Gets or sets a one-dimensional array of type String containing the culture-specific abbreviated names of the days of the week. |
AbbreviatedMonthNames | Read-write Gets or sets a one-dimensional array of type String containing the culture-specific abbreviated names of the months. |
AMDesignator | Read-write Gets or sets the string designator for hours that are "ante meridiem" (before noon). |
Calendar | Read-write Gets or sets the calendar to use for the current culture. |
CalendarWeekRule | Read-write Gets or sets a value that specifies which rule is used to determine the first calendar week of the year. |
CurrentInfo | Read-only Gets a read-only DateTimeFormatInfo that formats values based on the current culture. |
DateSeparator | Read-write Gets or sets the string that separates the components of a date; that is, the year, month, and day. |
DayNames | Read-write Gets or sets a one-dimensional array of type String containing the culture-specific full names of the days of the week. |
FirstDayOfWeek | Read-write Gets or sets the first day of the week. |
FullDateTimePattern | Read-write Gets or sets the format pattern for a long date and long time value, which is associated with the 'F' format character. |
InvariantInfo | Read-only Gets the default read-only DateTimeFormatInfo that is culture-independent (invariant). |
IsReadOnly | Read-only Gets a value indicating whether the DateTimeFormatInfo is read-only. |
LongDatePattern | Read-write Gets or sets the format pattern for a long date value, which is associated with the 'D' format character. |
LongTimePattern | Read-write Gets or sets the format pattern for a long time value, which is associated with the 'T' format character. |
MonthDayPattern | Read-write Gets or sets the format pattern for a month and day value, which is associated with the 'm' and 'M' format characters. |
MonthNames | Read-write Gets or sets a one-dimensional array of type String containing the culture-specific full names of the months. |
PMDesignator | Read-write Gets or sets the string designator for hours that are "post meridiem" (after noon). |
RFC1123Pattern | Read-only Gets the format pattern for a time value, which is based on the Internet Engineering Task Force (IETF) Request for Comments (RFC) 1123 specification and is associated with the 'r' and 'R' format characters. |
ShortDatePattern | Read-write Gets or sets the format pattern for a short date value, which is associated with the 'd' format character. |
ShortTimePattern | Read-write Gets or sets the format pattern for a short time value, which is associated with the 't' format character. |
SortableDateTimePattern | Read-only Gets the format pattern for a sortable date and time value, which is associated with the 's' format character. |
TimeSeparator | Read-write Gets or sets the string that separates the components of time; that is, the hour, minutes, and seconds. |
UniversalSortableDateTimePattern | Read-only Gets the format pattern for a universal sortable date and time value, which is associated with the 'u' and 'U' format characters. |
YearMonthPattern | Read-write Gets or sets the format pattern for a year and month value, which is associated with the 'y' and 'Y' format characters. |
Clone | Creates a shallow copy of the DateTimeFormatInfo. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetAbbreviatedDayName | Returns the culture-specific abbreviated name of the specified day of the week based on the CultureInfo of the current thread. |
GetAbbreviatedEraName | Returns the string containing the abbreviated name of the specified era, if an abbreviation exists. |
GetAbbreviatedMonthName | Returns the culture-specific abbreviated name of the specified month based on the CultureInfo of the current thread. |
GetAllDateTimePatterns | Overloaded:GetAllDateTimePatterns() Returns all the standard patterns in which DateTime values can be formatted. |
GetAllDateTimePatterns | Overloaded:GetAllDateTimePatterns(char format) Returns all the standard patterns in which DateTime values can be formatted using the specified format character. |
GetDayName | Returns the culture-specific full name of the specified day of the week based on the CultureInfo of the current thread. |
GetEra | Returns the integer representing the specified era. |
GetEraName | Returns the string containing the name of the specified era. |
GetFormat | Returns an object of the specified type that provides a DateTime formatting service. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetInstance | Returns the DateTimeFormatInfo associated with the specified IFormatProvider. |
GetMonthName | Returns the culture-specific full name of the specified month based on the CultureInfo of the current thread. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
ReadOnly | Returns a read-only DateTimeFormatInfo wrapper. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public DateTimeFormatInfo(); |
public string[] AbbreviatedDayNames {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
ArgumentException | The property is being set to an array that is multidimensional or whose length is not exactly 7. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
If the custom pattern includes the format pattern "ddd", DateTime.ToString displays the value of DateTimeFormatInfo.AbbreviatedDayNames in place of the "ddd" in the format pattern.
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes. If the selected DateTimeFormatInfo.Calendar does not support abbreviated day names, the array contains the full day names.
public string[] AbbreviatedMonthNames {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
ArgumentException | The property is being set to an array that is multidimensional or whose length is not exactly 13. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
If the custom pattern includes the format pattern "MMM", DateTime.ToString displays the value of DateTimeFormatInfo.AbbreviatedMonthNames in place of the "MMM" in the format pattern.
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes. If the selected DateTimeFormatInfo.Calendar does not support abbreviated month names, the array contains the full month names.
public string AMDesignator {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
public Calendar Calendar {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
ArgumentException | The property is being set to a Calendar that is not valid for the current culture. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
Changing the value of this property affects the following properties as well: DateTimeFormatInfo.MonthNames, DateTimeFormatInfo.AbbreviatedMonthNames, DateTimeFormatInfo.DayNames, DateTimeFormatInfo.AbbreviatedDayNames, DateTimeFormatInfo.CalendarWeekRule, DateTimeFormatInfo.FirstDayOfWeek, DateTimeFormatInfo.FullDateTimePattern, DateTimeFormatInfo.LongDatePattern, DateTimeFormatInfo.ShortDatePattern, DateTimeFormatInfo.YearMonthPattern, and DateTimeFormatInfo.MonthDayPattern.
For example, if the culture of the current thread is Japanese, this property accepts JapaneseCalendar, GregorianCalendarTypes.Localized GregorianCalendar, or GregorianCalendarTypes.USEnglish GregorianCalendar. When the JapaneseCalendar is used, the default long date pattern is "gg y'\x5e74'M'\x6708'd'\x65e5'". When the GregorianCalendarTypes.Localized GregorianCalendar, is used, the default long date pattern is "yyyy'\x5e74'M'\x6708'd'\x65e5'".
public CalendarWeekRule CalendarWeekRule {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The property is being set to a value that is not a valid CalendarWeekRule value. |
public static DateTimeFormatInfo CurrentInfo {get;}
|
public string DateSeparator {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
public string[] DayNames {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
ArgumentException | The property is being set to an array that is multidimensional or whose length is not exactly 7. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
If the custom pattern includes the format pattern "dddd", DateTime.ToString displays the value of DateTimeFormatInfo.DayNames in place of the "dddd" in the format pattern.
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes.
public DayOfWeek FirstDayOfWeek {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The property is being set to a value that is not a valid DayOfWeek value. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
public string FullDateTimePattern {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes.
public static DateTimeFormatInfo InvariantInfo {get;}
|
public bool IsReadOnly {get;}
|
public string LongDatePattern {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes.
public string LongTimePattern {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
public string MonthDayPattern {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes.
public string[] MonthNames {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
ArgumentException | The property is being set to an array that is multidimensional or whose length is not exactly 13. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
If the custom pattern includes the format pattern "MMMM", DateTime.ToString displays the value of DateTimeFormatInfo.MonthNames in place of the "MMMM" in the format pattern.
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes.
public string PMDesignator {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
public string RFC1123Pattern {get;}
|
public string ShortDatePattern {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes.
public string ShortTimePattern {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
public string SortableDateTimePattern {get;}
|
public string TimeSeparator {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
public string UniversalSortableDateTimePattern {get;}
|
public string YearMonthPattern {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The property is being set to null. |
InvalidOperationException | The property is being set and the DateTimeFormatInfo is read-only. |
This property is affected if the value of the DateTimeFormatInfo.Calendar property changes.
public object Clone(); |
A shallow copy of an object is a copy of the object only. If the object contains references to other objects, the shallow copy does not create copies of the referred objects. It refers to the original objects instead. In contrast, a deep copy of an object creates a copy of the object and a copy of everything directly or indirectly referenced by that object.
~DateTimeFormatInfo(); |
dayofweek
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | dayofweek is not a valid DayOfWeek value. |
Return Value | |
---|---|
Sunday | "Sun" |
Monday | "Mon" |
Tuesday | "Tue" |
Wednesday | "Wed" |
Thursday | "Thu" |
Friday | "Fri" |
Saturday | "Sat" |
era
-or-
A string containing the full name of the era, if an abbreviation does not exist.
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | era does not represent a valid era in the calendar specified in the DateTimeFormatInfo.Calendar property. |
The valid values for era are listed in the Calendar.Eras property of the appropriate class derived from Calendar. For example: JapaneseCalendar.Eras displays a list of eras that are supported by this implementation.
If the GregorianCalendar is selected in DateTimeFormatInfo.Calendar, DateTimeFormatInfo ignores punctuation in abbreviated era names; that is, "A.D." is equivalent to "AD".
In the JapaneseCalendar, the abbreviated era name is the first character of the full era name; that is, either the single-character case-insensitive Latin alphabet abbreviation or the single-character Kanji abbreviation.
month
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | month is less than 1 or greater than 13. |
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 | "" |
Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.
public string[] GetAllDateTimePatterns(); |
using System; using System.Globalization; public class SamplesDateTimeFormatInfo { public static void Main() { // Creates a new DateTimeFormatinfo. DateTimeFormatInfo myDtfi = new DateTimeFormatInfo(); // Gets and prints all the patterns. String[] myPatternsArray = myDtfi.GetAllDateTimePatterns(); Console.WriteLine( "ALL the patterns:" ); PrintIndexAndValues( myPatternsArray ); // Gets and prints the pattern(s) associated with some of the format characters. myPatternsArray = myDtfi.GetAllDateTimePatterns('d'); Console.WriteLine( "The patterns for 'd':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('D'); Console.WriteLine( "The patterns for 'D':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('f'); Console.WriteLine( "The patterns for 'f':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('F'); Console.WriteLine( "The patterns for 'F':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('r'); Console.WriteLine( "The patterns for 'r':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('R'); Console.WriteLine( "The patterns for 'R':" ); PrintIndexAndValues( myPatternsArray ); } public static void PrintIndexAndValues( String[] myArray ) { int i = 0; foreach ( String s in myArray ) Console.WriteLine( "\t[{0}]:\t{1}", i++, s ); Console.WriteLine(); } } /* This code produces the following output. ALL the patterns: [0]: MM/dd/yyyy [1]: M/d/yy [2]: MM/dd/yy [3]: M/d/yyyy [4]: yy/MM/dd [5]: yyyy-MM-dd [6]: dd-MMM-yy [7]: dddd, MMMM dd, yyyy [8]: MMMM dd, yyyy [9]: dddd, dd MMMM, yyyy [10]: dd MMMM, yyyy [11]: dddd, MMMM dd, yyyy HH:mm [12]: dddd, MMMM dd, yyyy hh:mm tt [13]: dddd, MMMM dd, yyyy H:mm [14]: dddd, MMMM dd, yyyy h:mm tt [15]: MMMM dd, yyyy HH:mm [16]: MMMM dd, yyyy hh:mm tt [17]: MMMM dd, yyyy H:mm [18]: MMMM dd, yyyy h:mm tt [19]: dddd, dd MMMM, yyyy HH:mm [20]: dddd, dd MMMM, yyyy hh:mm tt [21]: dddd, dd MMMM, yyyy H:mm [22]: dddd, dd MMMM, yyyy h:mm tt [23]: dd MMMM, yyyy HH:mm [24]: dd MMMM, yyyy hh:mm tt [25]: dd MMMM, yyyy H:mm [26]: dd MMMM, yyyy h:mm tt [27]: dddd, MMMM dd, yyyy HH:mm:ss [28]: dddd, MMMM dd, yyyy hh:mm:ss tt [29]: dddd, MMMM dd, yyyy H:mm:ss [30]: dddd, MMMM dd, yyyy h:mm:ss tt [31]: MMMM dd, yyyy HH:mm:ss [32]: MMMM dd, yyyy hh:mm:ss tt [33]: MMMM dd, yyyy H:mm:ss [34]: MMMM dd, yyyy h:mm:ss tt [35]: dddd, dd MMMM, yyyy HH:mm:ss [36]: dddd, dd MMMM, yyyy hh:mm:ss tt [37]: dddd, dd MMMM, yyyy H:mm:ss [38]: dddd, dd MMMM, yyyy h:mm:ss tt [39]: dd MMMM, yyyy HH:mm:ss [40]: dd MMMM, yyyy hh:mm:ss tt [41]: dd MMMM, yyyy H:mm:ss [42]: dd MMMM, yyyy h:mm:ss tt [43]: MM/dd/yyyy HH:mm [44]: MM/dd/yyyy hh:mm tt [45]: MM/dd/yyyy H:mm [46]: MM/dd/yyyy h:mm tt [47]: M/d/yy HH:mm [48]: M/d/yy hh:mm tt [49]: M/d/yy H:mm [50]: M/d/yy h:mm tt [51]: MM/dd/yy HH:mm [52]: MM/dd/yy hh:mm tt [53]: MM/dd/yy H:mm [54]: MM/dd/yy h:mm tt [55]: M/d/yyyy HH:mm [56]: M/d/yyyy hh:mm tt [57]: M/d/yyyy H:mm [58]: M/d/yyyy h:mm tt [59]: yy/MM/dd HH:mm [60]: yy/MM/dd hh:mm tt [61]: yy/MM/dd H:mm [62]: yy/MM/dd h:mm tt [63]: yyyy-MM-dd HH:mm [64]: yyyy-MM-dd hh:mm tt [65]: yyyy-MM-dd H:mm [66]: yyyy-MM-dd h:mm tt [67]: dd-MMM-yy HH:mm [68]: dd-MMM-yy hh:mm tt [69]: dd-MMM-yy H:mm [70]: dd-MMM-yy h:mm tt [71]: MM/dd/yyyy HH:mm:ss [72]: MM/dd/yyyy hh:mm:ss tt [73]: MM/dd/yyyy H:mm:ss [74]: MM/dd/yyyy h:mm:ss tt [75]: M/d/yy HH:mm:ss [76]: M/d/yy hh:mm:ss tt [77]: M/d/yy H:mm:ss [78]: M/d/yy h:mm:ss tt [79]: MM/dd/yy HH:mm:ss [80]: MM/dd/yy hh:mm:ss tt [81]: MM/dd/yy H:mm:ss [82]: MM/dd/yy h:mm:ss tt [83]: M/d/yyyy HH:mm:ss [84]: M/d/yyyy hh:mm:ss tt [85]: M/d/yyyy H:mm:ss [86]: M/d/yyyy h:mm:ss tt [87]: yy/MM/dd HH:mm:ss [88]: yy/MM/dd hh:mm:ss tt [89]: yy/MM/dd H:mm:ss [90]: yy/MM/dd h:mm:ss tt [91]: yyyy-MM-dd HH:mm:ss [92]: yyyy-MM-dd hh:mm:ss tt [93]: yyyy-MM-dd H:mm:ss [94]: yyyy-MM-dd h:mm:ss tt [95]: dd-MMM-yy HH:mm:ss [96]: dd-MMM-yy hh:mm:ss tt [97]: dd-MMM-yy H:mm:ss [98]: dd-MMM-yy h:mm:ss tt [99]: MMMM dd [100]: MMMM dd [101]: ddd, dd MMM yyyy HH':'mm':'ss 'GMT' [102]: ddd, dd MMM yyyy HH':'mm':'ss 'GMT' [103]: yyyy-MM-dd HH:mm:ss [104]: HH:mm [105]: hh:mm tt [106]: H:mm [107]: h:mm tt [108]: HH:mm:ss [109]: hh:mm:ss tt [110]: H:mm:ss [111]: h:mm:ss tt [112]: yyyy-MM-dd HH:mm:ss [113]: dddd, MMMM dd, yyyy HH:mm:ss [114]: dddd, MMMM dd, yyyy hh:mm:ss tt [115]: dddd, MMMM dd, yyyy H:mm:ss [116]: dddd, MMMM dd, yyyy h:mm:ss tt [117]: MMMM dd, yyyy HH:mm:ss [118]: MMMM dd, yyyy hh:mm:ss tt [119]: MMMM dd, yyyy H:mm:ss [120]: MMMM dd, yyyy h:mm:ss tt [121]: dddd, dd MMMM, yyyy HH:mm:ss [122]: dddd, dd MMMM, yyyy hh:mm:ss tt [123]: dddd, dd MMMM, yyyy H:mm:ss [124]: dddd, dd MMMM, yyyy h:mm:ss tt [125]: dd MMMM, yyyy HH:mm:ss [126]: dd MMMM, yyyy hh:mm:ss tt [127]: dd MMMM, yyyy H:mm:ss [128]: dd MMMM, yyyy h:mm:ss tt [129]: MMMM, yyyy [130]: MMMM, yyyy The patterns for 'd': [0]: MM/dd/yyyy [1]: M/d/yy [2]: MM/dd/yy [3]: M/d/yyyy [4]: yy/MM/dd [5]: yyyy-MM-dd [6]: dd-MMM-yy The patterns for 'D': [0]: dddd, MMMM dd, yyyy [1]: MMMM dd, yyyy [2]: dddd, dd MMMM, yyyy [3]: dd MMMM, yyyy The patterns for 'f': [0]: dddd, MMMM dd, yyyy HH:mm [1]: dddd, MMMM dd, yyyy hh:mm tt [2]: dddd, MMMM dd, yyyy H:mm [3]: dddd, MMMM dd, yyyy h:mm tt [4]: MMMM dd, yyyy HH:mm [5]: MMMM dd, yyyy hh:mm tt [6]: MMMM dd, yyyy H:mm [7]: MMMM dd, yyyy h:mm tt [8]: dddd, dd MMMM, yyyy HH:mm [9]: dddd, dd MMMM, yyyy hh:mm tt [10]: dddd, dd MMMM, yyyy H:mm [11]: dddd, dd MMMM, yyyy h:mm tt [12]: dd MMMM, yyyy HH:mm [13]: dd MMMM, yyyy hh:mm tt [14]: dd MMMM, yyyy H:mm [15]: dd MMMM, yyyy h:mm tt The patterns for 'F': [0]: dddd, MMMM dd, yyyy HH:mm:ss [1]: dddd, MMMM dd, yyyy hh:mm:ss tt [2]: dddd, MMMM dd, yyyy H:mm:ss [3]: dddd, MMMM dd, yyyy h:mm:ss tt [4]: MMMM dd, yyyy HH:mm:ss [5]: MMMM dd, yyyy hh:mm:ss tt [6]: MMMM dd, yyyy H:mm:ss [7]: MMMM dd, yyyy h:mm:ss tt [8]: dddd, dd MMMM, yyyy HH:mm:ss [9]: dddd, dd MMMM, yyyy hh:mm:ss tt [10]: dddd, dd MMMM, yyyy H:mm:ss [11]: dddd, dd MMMM, yyyy h:mm:ss tt [12]: dd MMMM, yyyy HH:mm:ss [13]: dd MMMM, yyyy hh:mm:ss tt [14]: dd MMMM, yyyy H:mm:ss [15]: dd MMMM, yyyy h:mm:ss tt The patterns for 'r': [0]: ddd, dd MMM yyyy HH':'mm':'ss 'GMT' The patterns for 'R': [0]: ddd, dd MMM yyyy HH':'mm':'ss 'GMT' */
format
Exception Type | Condition |
---|---|
ArgumentException | format is not a valid standard format character. |
using System; using System.Globalization; public class SamplesDateTimeFormatInfo { public static void Main() { // Creates a new DateTimeFormatinfo. DateTimeFormatInfo myDtfi = new DateTimeFormatInfo(); // Gets and prints all the patterns. String[] myPatternsArray = myDtfi.GetAllDateTimePatterns(); Console.WriteLine( "ALL the patterns:" ); PrintIndexAndValues( myPatternsArray ); // Gets and prints the pattern(s) associated with some of the format characters. myPatternsArray = myDtfi.GetAllDateTimePatterns('d'); Console.WriteLine( "The patterns for 'd':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('D'); Console.WriteLine( "The patterns for 'D':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('f'); Console.WriteLine( "The patterns for 'f':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('F'); Console.WriteLine( "The patterns for 'F':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('r'); Console.WriteLine( "The patterns for 'r':" ); PrintIndexAndValues( myPatternsArray ); myPatternsArray = myDtfi.GetAllDateTimePatterns('R'); Console.WriteLine( "The patterns for 'R':" ); PrintIndexAndValues( myPatternsArray ); } public static void PrintIndexAndValues( String[] myArray ) { int i = 0; foreach ( String s in myArray ) Console.WriteLine( "\t[{0}]:\t{1}", i++, s ); Console.WriteLine(); } } /* This code produces the following output. ALL the patterns: [0]: MM/dd/yyyy [1]: M/d/yy [2]: MM/dd/yy [3]: M/d/yyyy [4]: yy/MM/dd [5]: yyyy-MM-dd [6]: dd-MMM-yy [7]: dddd, MMMM dd, yyyy [8]: MMMM dd, yyyy [9]: dddd, dd MMMM, yyyy [10]: dd MMMM, yyyy [11]: dddd, MMMM dd, yyyy HH:mm [12]: dddd, MMMM dd, yyyy hh:mm tt [13]: dddd, MMMM dd, yyyy H:mm [14]: dddd, MMMM dd, yyyy h:mm tt [15]: MMMM dd, yyyy HH:mm [16]: MMMM dd, yyyy hh:mm tt [17]: MMMM dd, yyyy H:mm [18]: MMMM dd, yyyy h:mm tt [19]: dddd, dd MMMM, yyyy HH:mm [20]: dddd, dd MMMM, yyyy hh:mm tt [21]: dddd, dd MMMM, yyyy H:mm [22]: dddd, dd MMMM, yyyy h:mm tt [23]: dd MMMM, yyyy HH:mm [24]: dd MMMM, yyyy hh:mm tt [25]: dd MMMM, yyyy H:mm [26]: dd MMMM, yyyy h:mm tt [27]: dddd, MMMM dd, yyyy HH:mm:ss [28]: dddd, MMMM dd, yyyy hh:mm:ss tt [29]: dddd, MMMM dd, yyyy H:mm:ss [30]: dddd, MMMM dd, yyyy h:mm:ss tt [31]: MMMM dd, yyyy HH:mm:ss [32]: MMMM dd, yyyy hh:mm:ss tt [33]: MMMM dd, yyyy H:mm:ss [34]: MMMM dd, yyyy h:mm:ss tt [35]: dddd, dd MMMM, yyyy HH:mm:ss [36]: dddd, dd MMMM, yyyy hh:mm:ss tt [37]: dddd, dd MMMM, yyyy H:mm:ss [38]: dddd, dd MMMM, yyyy h:mm:ss tt [39]: dd MMMM, yyyy HH:mm:ss [40]: dd MMMM, yyyy hh:mm:ss tt [41]: dd MMMM, yyyy H:mm:ss [42]: dd MMMM, yyyy h:mm:ss tt [43]: MM/dd/yyyy HH:mm [44]: MM/dd/yyyy hh:mm tt [45]: MM/dd/yyyy H:mm [46]: MM/dd/yyyy h:mm tt [47]: M/d/yy HH:mm [48]: M/d/yy hh:mm tt [49]: M/d/yy H:mm [50]: M/d/yy h:mm tt [51]: MM/dd/yy HH:mm [52]: MM/dd/yy hh:mm tt [53]: MM/dd/yy H:mm [54]: MM/dd/yy h:mm tt [55]: M/d/yyyy HH:mm [56]: M/d/yyyy hh:mm tt [57]: M/d/yyyy H:mm [58]: M/d/yyyy h:mm tt [59]: yy/MM/dd HH:mm [60]: yy/MM/dd hh:mm tt [61]: yy/MM/dd H:mm [62]: yy/MM/dd h:mm tt [63]: yyyy-MM-dd HH:mm [64]: yyyy-MM-dd hh:mm tt [65]: yyyy-MM-dd H:mm [66]: yyyy-MM-dd h:mm tt [67]: dd-MMM-yy HH:mm [68]: dd-MMM-yy hh:mm tt [69]: dd-MMM-yy H:mm [70]: dd-MMM-yy h:mm tt [71]: MM/dd/yyyy HH:mm:ss [72]: MM/dd/yyyy hh:mm:ss tt [73]: MM/dd/yyyy H:mm:ss [74]: MM/dd/yyyy h:mm:ss tt [75]: M/d/yy HH:mm:ss [76]: M/d/yy hh:mm:ss tt [77]: M/d/yy H:mm:ss [78]: M/d/yy h:mm:ss tt [79]: MM/dd/yy HH:mm:ss [80]: MM/dd/yy hh:mm:ss tt [81]: MM/dd/yy H:mm:ss [82]: MM/dd/yy h:mm:ss tt [83]: M/d/yyyy HH:mm:ss [84]: M/d/yyyy hh:mm:ss tt [85]: M/d/yyyy H:mm:ss [86]: M/d/yyyy h:mm:ss tt [87]: yy/MM/dd HH:mm:ss [88]: yy/MM/dd hh:mm:ss tt [89]: yy/MM/dd H:mm:ss [90]: yy/MM/dd h:mm:ss tt [91]: yyyy-MM-dd HH:mm:ss [92]: yyyy-MM-dd hh:mm:ss tt [93]: yyyy-MM-dd H:mm:ss [94]: yyyy-MM-dd h:mm:ss tt [95]: dd-MMM-yy HH:mm:ss [96]: dd-MMM-yy hh:mm:ss tt [97]: dd-MMM-yy H:mm:ss [98]: dd-MMM-yy h:mm:ss tt [99]: MMMM dd [100]: MMMM dd [101]: ddd, dd MMM yyyy HH':'mm':'ss 'GMT' [102]: ddd, dd MMM yyyy HH':'mm':'ss 'GMT' [103]: yyyy-MM-dd HH:mm:ss [104]: HH:mm [105]: hh:mm tt [106]: H:mm [107]: h:mm tt [108]: HH:mm:ss [109]: hh:mm:ss tt [110]: H:mm:ss [111]: h:mm:ss tt [112]: yyyy-MM-dd HH:mm:ss [113]: dddd, MMMM dd, yyyy HH:mm:ss [114]: dddd, MMMM dd, yyyy hh:mm:ss tt [115]: dddd, MMMM dd, yyyy H:mm:ss [116]: dddd, MMMM dd, yyyy h:mm:ss tt [117]: MMMM dd, yyyy HH:mm:ss [118]: MMMM dd, yyyy hh:mm:ss tt [119]: MMMM dd, yyyy H:mm:ss [120]: MMMM dd, yyyy h:mm:ss tt [121]: dddd, dd MMMM, yyyy HH:mm:ss [122]: dddd, dd MMMM, yyyy hh:mm:ss tt [123]: dddd, dd MMMM, yyyy H:mm:ss [124]: dddd, dd MMMM, yyyy h:mm:ss tt [125]: dd MMMM, yyyy HH:mm:ss [126]: dd MMMM, yyyy hh:mm:ss tt [127]: dd MMMM, yyyy H:mm:ss [128]: dd MMMM, yyyy h:mm:ss tt [129]: MMMM, yyyy [130]: MMMM, yyyy The patterns for 'd': [0]: MM/dd/yyyy [1]: M/d/yy [2]: MM/dd/yy [3]: M/d/yyyy [4]: yy/MM/dd [5]: yyyy-MM-dd [6]: dd-MMM-yy The patterns for 'D': [0]: dddd, MMMM dd, yyyy [1]: MMMM dd, yyyy [2]: dddd, dd MMMM, yyyy [3]: dd MMMM, yyyy The patterns for 'f': [0]: dddd, MMMM dd, yyyy HH:mm [1]: dddd, MMMM dd, yyyy hh:mm tt [2]: dddd, MMMM dd, yyyy H:mm [3]: dddd, MMMM dd, yyyy h:mm tt [4]: MMMM dd, yyyy HH:mm [5]: MMMM dd, yyyy hh:mm tt [6]: MMMM dd, yyyy H:mm [7]: MMMM dd, yyyy h:mm tt [8]: dddd, dd MMMM, yyyy HH:mm [9]: dddd, dd MMMM, yyyy hh:mm tt [10]: dddd, dd MMMM, yyyy H:mm [11]: dddd, dd MMMM, yyyy h:mm tt [12]: dd MMMM, yyyy HH:mm [13]: dd MMMM, yyyy hh:mm tt [14]: dd MMMM, yyyy H:mm [15]: dd MMMM, yyyy h:mm tt The patterns for 'F': [0]: dddd, MMMM dd, yyyy HH:mm:ss [1]: dddd, MMMM dd, yyyy hh:mm:ss tt [2]: dddd, MMMM dd, yyyy H:mm:ss [3]: dddd, MMMM dd, yyyy h:mm:ss tt [4]: MMMM dd, yyyy HH:mm:ss [5]: MMMM dd, yyyy hh:mm:ss tt [6]: MMMM dd, yyyy H:mm:ss [7]: MMMM dd, yyyy h:mm:ss tt [8]: dddd, dd MMMM, yyyy HH:mm:ss [9]: dddd, dd MMMM, yyyy hh:mm:ss tt [10]: dddd, dd MMMM, yyyy H:mm:ss [11]: dddd, dd MMMM, yyyy h:mm:ss tt [12]: dd MMMM, yyyy HH:mm:ss [13]: dd MMMM, yyyy hh:mm:ss tt [14]: dd MMMM, yyyy H:mm:ss [15]: dd MMMM, yyyy h:mm:ss tt The patterns for 'r': [0]: ddd, dd MMM yyyy HH':'mm':'ss 'GMT' The patterns for 'R': [0]: ddd, dd MMM yyyy HH':'mm':'ss 'GMT' */
dayofweek
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | dayofweek is not a valid DayOfWeek value. |
Return Value | |
---|---|
Sunday | "Sunday" |
Monday | "Monday" |
Tuesday | "Tuesday" |
Wednesday | "Wednesday" |
Thursday | "Thursday" |
Friday | "Friday" |
Saturday | "Saturday" |
eraName
Exception Type | Condition |
---|---|
ArgumentNullException | eraName is null. |
The comparison with eraName is case-insensitive; for example, "A.D." is equivalent to "a.d.".
If the GregorianCalendar is selected in DateTimeFormatInfo.Calendar, DateTimeFormatInfo ignores punctuation in abbreviated era names; that is, "A.D." is equivalent to "AD".
DateTimeFormatInfo.GetEra compares eraName with the full era name returned by DateTimeFormatInfo.GetEraName and with the abbreviated era name returned by DateTimeFormatInfo.GetAbbreviatedEraName.
era
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | era does not represent a valid era in the calendar specified in the DateTimeFormatInfo.Calendar property. |
The valid values for era are listed in the Calendar.Eras property of the appropriate class derived from Calendar. For example: JapaneseCalendar.Eras displays a list of eras that are supported by this implementation.
formatType
public virtual int GetHashCode(); |
public static DateTimeFormatInfo GetInstance( |
provider
-or-
null to get DateTimeFormatInfo.CurrentInfo.
The IFormatProvider that gets the DateTimeFormatInfo.-or-
null to get DateTimeFormatInfo.CurrentInfo.
You can get a DateTimeFormatInfo for a specific culture using one of the following methods:
A DateTimeFormatInfo can be created only for the invariant culture or for specific cultures, not for neutral cultures. For more information about the invariant culture, specific cultures, and neutral cultures, see the CultureInfo class.
month
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | month is less than 1 or greater than 13. |
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 | "" |
Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.
public Type GetType(); |
protected object MemberwiseClone(); |
public static DateTimeFormatInfo ReadOnly( |
dtfi
Exception Type | Condition |
---|---|
ArgumentNullException | dtfi is null. |
public virtual string ToString(); |