Skip to main content
.NET Framework Class Library
ConvertToString 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)
Syntax
Public Shared Function ToString ( _
	value As [%$TOPIC/ms131008_en-us_VS_110_2_0_0_0_0%], _
	provider As [%$TOPIC/ms131008_en-us_VS_110_2_0_0_0_1%] _
) As [%$TOPIC/ms131008_en-us_VS_110_2_0_0_0_2%]
public static [%$TOPIC/ms131008_en-us_VS_110_2_0_1_0_0%] ToString(
	[%$TOPIC/ms131008_en-us_VS_110_2_0_1_0_1%] value,
	[%$TOPIC/ms131008_en-us_VS_110_2_0_1_0_2%] provider
)
public:
static [%$TOPIC/ms131008_en-us_VS_110_2_0_2_0_0%]^ ToString(
	[%$TOPIC/ms131008_en-us_VS_110_2_0_2_0_1%] value, 
	[%$TOPIC/ms131008_en-us_VS_110_2_0_2_0_2%]^ provider
)
static member ToString : 
        value:[%$TOPIC/ms131008_en-us_VS_110_2_0_3_0_0%] * 
        provider:[%$TOPIC/ms131008_en-us_VS_110_2_0_3_0_1%] -> [%$TOPIC/ms131008_en-us_VS_110_2_0_3_0_2%]
public static function ToString(
	value : [%$TOPIC/ms131008_en-us_VS_110_2_0_4_0_0%], 
	provider : [%$TOPIC/ms131008_en-us_VS_110_2_0_4_0_1%]
) : [%$TOPIC/ms131008_en-us_VS_110_2_0_4_0_2%]

Parameters

value
Type: SystemDateTime

The date and time value to convert.

provider
Type: SystemIFormatProvider

An object that supplies culture-specific formatting information.

Return Value

Type: SystemString
The string representation of value.
Remarks

This implementation is identical to DateTimeToString(IFormatProvider).

Examples

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. 
Dim tDate As New Date(2010, 4, 15, 20, 30, 40, 333)
' Specify the cultures. 
Dim cultureNames() As String = { "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))

For Each cultureName As String In CultureNames
   Dim culture As New System.Globalization.CultureInfo(cultureName)
   Dim dateString As String = Convert.ToString(tDate, culture)
   Console.WriteLine("   {0}:  {1,-12}", _
                     culture.Name, dateString)
Next              
' 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      
// 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      
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8