Export (0) Print
Expand All

Convert.ToString Method (DateTime, IFormatProvider)

Converts the value of the specified DateTime to its equivalent string representation, using the specified culture-specific formatting information.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static string ToString(
	DateTime value,
	IFormatProvider provider
)

Parameters

value
Type: System.DateTime

The date and time value to convert.

provider
Type: System.IFormatProvider

An object that supplies culture-specific formatting information.

Return Value

Type: System.String
The string representation of value.

This implementation is identical to DateTime.ToString(IFormatProvider).

The following example converts a DateTime value to its equivalent string representation in eight different cultures.

// Specify the date to be formatted using various cultures.
DateTime tDate = new DateTime(2010, 4, 15, 20, 30, 40, 333);
// Specify the cultures.
string[] cultureNames = { "en-US", "es-AR", "fr-FR", "hi-IN",
                          "ja-JP", "nl-NL", "ru-RU", "ur-PK" };

Console.WriteLine("Converting the date {0}: ", 
                  Convert.ToString(tDate, 
                          System.Globalization.CultureInfo.InvariantCulture));

foreach (string cultureName in cultureNames)
{
   System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cultureName);
   string dateString = Convert.ToString(tDate, culture);
   Console.WriteLine("   {0}:  {1,-12}", 
                     culture.Name, dateString);
}             
// The example displays the following output: 
//       Converting the date 04/15/2010 20:30:40: 
//          en-US:  4/15/2010 8:30:40 PM 
//          es-AR:  15/04/2010 08:30:40 p.m. 
//          fr-FR:  15/04/2010 20:30:40 
//          hi-IN:  15-04-2010 20:30:40 
//          ja-JP:  2010/04/15 20:30:40 
//          nl-NL:  15-4-2010 20:30:40 
//          ru-RU:  15.04.2010 20:30:40 
//          ur-PK:  15/04/2010 8:30:40 PM      

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft