정보
요청한 주제가 아래에 표시됩니다. 그러나 이 주제는 이 라이브러리에 포함되지 않습니다.

Convert.ToString 메서드 (DateTime, IFormatProvider)

2013-12-13

지정된 DateTime의 값을 String 표현으로 변환합니다.

Namespace:  System
어셈블리:  mscorlib(mscorlib.dll)

public static string ToString(
	DateTime value,
	IFormatProvider provider
)

매개 변수

value
형식: System.DateTime
DateTime입니다.
provider
형식: System.IFormatProvider
문화권별 형식 정보를 제공하는 IFormatProvider 인터페이스의 구현입니다.

반환 값

형식: System.String
value의 값에 해당하는 String을 반환합니다.

이 구현은 DateTime.ToString과 동일합니다.

다음 코드 예제에서는 ToString 메서드에 IFormatProvider 개체를 사용하여 DateTime 값을 String으로 변환합니다.


// Example of the Convert.ToString( DateTime ) and 
// Convert.ToString( DateTime, IFormatProvider ) methods.
using System;
using System.Globalization;

class Example
{
   static void DisplayDateNCultureName(System.Windows.Controls.TextBlock outputBlock, DateTime testDate,
       string cultureName)
   {
      // Create the CultureInfo object for the specified culture,
      // and use it as the IFormatProvider when converting the date.
      CultureInfo culture = new CultureInfo(cultureName);
      string dateString = Convert.ToString(testDate, culture);

      // Bracket the culture name, and display the name and date.
      outputBlock.Text += String.Format("   {0,-12}{1}",
          String.Concat("[", cultureName, "]"), dateString) + "\n";
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Specify the date to be formatted under various cultures.
      DateTime tDate = new DateTime(2003, 4, 15, 20, 30, 40, 333);

      outputBlock.Text += String.Format("This example of \n" +
          "   Convert.ToString( DateTime ) and \n" +
          "   Convert.ToString( DateTime, IFormatProvider )\n" +
          "generates the following output. It creates " +
          "CultureInfo objects \nfor several cultures " +
          "and formats a DateTime value with each.\n") + "\n";

      // Format the date without an IFormatProvider.
      outputBlock.Text += String.Format("   {0,-12}{1}",
          null, "No IFormatProvider") + "\n";
      outputBlock.Text += String.Format("   {0,-12}{1}",
          null, "------------------") + "\n";
      outputBlock.Text += String.Format("   {0,-12}{1}\n",
          String.Concat("[", CultureInfo.CurrentCulture.Name, "]"),
          Convert.ToString(tDate)) + "\n";

      // Format the date with IFormatProvider for several cultures.
      outputBlock.Text += String.Format("   {0,-12}{1}",
          "Culture", "With IFormatProvider") + "\n";
      outputBlock.Text += String.Format("   {0,-12}{1}",
          "-------", "--------------------") + "\n";

      DisplayDateNCultureName(outputBlock, tDate, "");
      DisplayDateNCultureName(outputBlock, tDate, "en-US");
      DisplayDateNCultureName(outputBlock, tDate, "es-AR");
      DisplayDateNCultureName(outputBlock, tDate, "fr-FR");
      DisplayDateNCultureName(outputBlock, tDate, "hi-IN");
      DisplayDateNCultureName(outputBlock, tDate, "ja-JP");
      DisplayDateNCultureName(outputBlock, tDate, "nl-NL");
      DisplayDateNCultureName(outputBlock, tDate, "ru-RU");
      DisplayDateNCultureName(outputBlock, tDate, "ur-PK");
   }
}

/*
This example of
   Convert.ToString( DateTime ) and
   Convert.ToString( DateTime, IFormatProvider )
generates the following output. It creates CultureInfo objects
for several cultures and formats a DateTime value with each.

               No IFormatProvider
               ------------------
   [en-US]     4/15/2003 8:30:40 PM

   Culture     With IFormatProvider
   -------     --------------------
   []          04/15/2003 20:30:40
   [en-US]     4/15/2003 8:30:40 PM
   [es-AR]     15/04/2003 08:30:40 p.m.
   [fr-FR]     15/04/2003 20:30:40
   [hi-IN]     15-04-2003 20:30:40
   [ja-JP]     2003/04/15 20:30:40
   [nl-NL]     15-4-2003 20:30:40
   [ru-RU]     15.04.2003 20:30:40
   [ur-PK]     15/04/2003 8:30:40 PM
*/


Windows Phone OS

지원되는 버전: 8.0, 7.1, 7.0

Windows Phone

표시: