Converts the value of this instance to all the string representations supported by the standard date and time format specifiers and the specified culture-specific formatting information.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Parameters
- provider
- Type: System.IFormatProvider
An object that supplies culture-specific formatting information about this instance.
Return Value
Type: System.String[]A string array where each element is the representation of the value of this instance formatted with one of the standard date and time format specifiers.
The string array returned by the DateTime.GetDateTimeFormats(IFormatProvider) method is equivalent to combining the string arrays returned by separate calls to the DateTime.GetDateTimeFormats(Char, IFormatProvider) method with the "d", "D", "f", "F", "g", "G", "m", "o", "r", "s", "t", "T", "u", "U", and "y" standard format strings. For more information about standard format specifiers, see Standard Date and Time Format Strings.
Each element of the return value is formatted using culture-specific information supplied by provider.
Important |
|---|
Because this method uses culture-sensitive data, you should not assume that multiple calls to the method will return identical data unless provider is a CultureInfo object that represents the invariant culture. The data returned by this method can change if the user overrides the individual cultural settings of provider or if an update occurs to the system's cultural data for provider. |
The following example demonstrates the DateTime.GetDateTimeFormats(IFormatProvider) method. It displays the string representation of a date using all possible standard date and time formats for the fr-FR culture.
DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15, 16); IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true); // Get the short date formats using the "fr-FR" culture. string [] frenchJuly28Formats = july28.GetDateTimeFormats(culture); // Display july28 in various formats using "fr-FR" culture. foreach (string format in frenchJuly28Formats) { Console.WriteLine(format); }
The example displays the following output:
28/07/2009 28/07/09 28.07.09 28-07-09 2009-07-28 mardi 28 juillet 2009 28 juil. 09 28 juillet 2009 mardi 28 juillet 2009 05:23 mardi 28 juillet 2009 5:23 mardi 28 juillet 2009 05.23 mardi 28 juillet 2009 05 h 23 28 juil. 09 05:23 28 juil. 09 5:23 28 juil. 09 05.23 28 juil. 09 05 h 23 28 juillet 2009 05:23 28 juillet 2009 5:23 28 juillet 2009 05.23 28 juillet 2009 05 h 23 mardi 28 juillet 2009 05:23:15 mardi 28 juillet 2009 5:23:15 mardi 28 juillet 2009 05.23 mardi 28 juillet 2009 05 h 23 28 juil. 09 05:23:15 28 juil. 09 5:23:15 28 juil. 09 05.23 28 juil. 09 05 h 23 28 juillet 2009 05:23:15 28 juillet 2009 5:23:15 28 juillet 2009 05.23 28 juillet 2009 05 h 23 28/07/2009 05:23 28/07/2009 5:23 28/07/2009 05.23 28/07/2009 05 h 23 28/07/09 05:23 28/07/09 5:23 28/07/09 05.23 28/07/09 05 h 23 28.07.09 05:23 28.07.09 5:23 28.07.09 05.23 28.07.09 05 h 23 28-07-09 05:23 28-07-09 5:23 28-07-09 05.23 28-07-09 05 h 23 2009-07-28 05:23 2009-07-28 5:23 2009-07-28 05.23 2009-07-28 05 h 23 28/07/2009 05:23:15 28/07/2009 5:23:15 28/07/2009 05.23 28/07/2009 05 h 23 28/07/09 05:23:15 28/07/09 5:23:15 28/07/09 05.23 28/07/09 05 h 23 28.07.09 05:23:15 28.07.09 5:23:15 28.07.09 05.23 28.07.09 05 h 23 28-07-09 05:23:15 28-07-09 5:23:15 28-07-09 05.23 28-07-09 05 h 23 2009-07-28 05:23:15 2009-07-28 5:23:15 2009-07-28 05.23 2009-07-28 05 h 23 28 juillet 28 juillet 2009-07-28T05:23:15.0160000 2009-07-28T05:23:15.0160000 Tue, 28 Jul 2009 05:23:15 GMT Tue, 28 Jul 2009 05:23:15 GMT 2009-07-28T05:23:15 05:23 5:23 05.23 05 h 23 05:23:15 5:23:15 05.23 05 h 23 2009-07-28 05:23:15Z mardi 28 juillet 2009 12:23:15 mardi 28 juillet 2009 12:23:15 mardi 28 juillet 2009 12.23 mardi 28 juillet 2009 12 h 23 28 juil. 09 12:23:15 28 juil. 09 12:23:15 28 juil. 09 12.23 28 juil. 09 12 h 23 28 juillet 2009 12:23:15 28 juillet 2009 12:23:15 28 juillet 2009 12.23 28 juillet 2009 12 h 23 juillet 2009 juillet 2009
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Important