DateTime.ToShortDateString メソッド

定義

現在の DateTime オブジェクトの値を、それと等価な短い形式の日付の文字列形式に変換します。Converts the value of the current DateTime object to its equivalent short date string representation.

public:
 System::String ^ ToShortDateString();
public string ToShortDateString ();
member this.ToShortDateString : unit -> string
Public Function ToShortDateString () As String

戻り値

現在の DateTime オブジェクトを短い形式の日付で表した文字列。A string that contains the short date string representation of the current DateTime object.

ToShortDateStringメソッドの例を次に示します。The following example demonstrates the ToShortDateString method. また、ToShortDateString メソッドを呼び出した結果が、format パラメーターとして "d" を指定した DateTime.ToString(String) メソッドを呼び出すことと同じであることがわかります。It also shows that the result of calling the ToShortDateString method is identical to calling the DateTime.ToString(String) method with "d" as the format parameter.

using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Main()
   {
      DateTime dateToDisplay = new DateTime(2009, 6, 1, 8, 42, 50);
      CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
      // Change culture to en-US.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
      Console.WriteLine("Displaying short date for {0} culture:", 
                        Thread.CurrentThread.CurrentCulture.Name);
      Console.WriteLine("   {0} (Short Date String)", 
                        dateToDisplay.ToShortDateString());
      // Display using 'd' standard format specifier to illustrate it is
      // identical to the string returned by ToShortDateString.
      Console.WriteLine("   {0} ('d' standard format specifier)", 
                        dateToDisplay.ToString("d"));
      Console.WriteLine();
      
      // Change culture to fr-FR.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
      Console.WriteLine("Displaying short date for {0} culture:", 
                        Thread.CurrentThread.CurrentCulture.Name);
      Console.WriteLine("   {0}", dateToDisplay.ToShortDateString());
      Console.WriteLine();
  
      // Change culture to nl-NL.    
      Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-NL");
      Console.WriteLine("Displaying short date for {0} culture:", 
                        Thread.CurrentThread.CurrentCulture.Name);
      Console.WriteLine("   {0}", dateToDisplay.ToShortDateString());
      
      // Restore original culture.
      Thread.CurrentThread.CurrentCulture = originalCulture;
   }
}
// The example displays the following output:
//       Displaying short date for en-US culture:
//          6/1/2009 (Short Date String)
//          6/1/2009 ('d' standard format specifier)
//       
//       Displaying short date for fr-FR culture:
//          01/06/2009
//       
//       Displaying short date for nl-NL culture:
//          1-6-2009
Imports System.Globalization
Imports System.Threading

Module Example
   Public Sub Main()
      Dim dateToDisplay As Date = #06/01/2009 8:42:50#
      Dim originalCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
      ' Change culture to en-US.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
      Console.WriteLine("Displaying short date for {0} culture:", _
                        Thread.CurrentThread.CurrentCulture.Name)
      Console.WriteLine("   {0} (Short Date String)", _
                        dateToDisplay.ToShortDateString())
      ' Display using 'd' standard format specifier to illustrate it is
      ' identical to the string returned by ToShortDateString.
      Console.WriteLine("   {0} ('d' standard format specifier)", _
                        dateToDisplay.ToString("d"))
      Console.WriteLine()
      
      ' Change culture to fr-FR.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("fr-FR")
      Console.WriteLine("Displaying short date for {0} culture:", _
                        Thread.CurrentThread.CurrentCulture.Name)
      Console.WriteLine("   {0}", dateToDisplay.ToShortDateString())
      Console.WriteLine()
  
      ' Change culture to nl-NL.    
      Thread.CurrentThread.CurrentCulture = New CultureInfo("nl-NL")
      Console.WriteLine("Displaying short date for {0} culture:", _
                        Thread.CurrentThread.CurrentCulture.Name)
      Console.WriteLine("   {0}", dateToDisplay.ToShortDateString())
      
      ' Restore original culture.
      Thread.CurrentThread.CurrentCulture = originalCulture
   End Sub
End Module
' The example displays the following output:
'       Displaying short date for en-US culture:
'          6/1/2009 (Short Date String)
'          6/1/2009 ('d' standard format specifier)
'       
'       Displaying short date for fr-FR culture:
'          01/06/2009
'       
'       Displaying short date for nl-NL culture:
'          1-6-2009

注釈

現在の DateTime オブジェクトの値は、現在のスレッドカルチャに関連付けられている DateTimeFormatInfo.ShortDatePattern プロパティによって定義されたパターンを使用して書式設定されます。The value of the current DateTime object is formatted using the pattern defined by the DateTimeFormatInfo.ShortDatePattern property associated with the current thread culture. 戻り値は、ToString(String) メソッドを使用して、標準の DateTime 書式指定文字列"d" を指定することによって返される値と同じです。The return value is identical to the value returned by specifying the "d" standard DateTime format string with the ToString(String) method.

注意

ToShortDateString メソッドによって返される文字列は、カルチャに依存します。The string returned by the ToShortDateString method is culture-sensitive. このメソッドは、現在のカルチャの DateTimeFormatInfo.ShortDatePattern プロパティによって定義されたパターンを反映します。It reflects the pattern defined by the current culture's DateTimeFormatInfo.ShortDatePattern property. たとえば、en-us カルチャでは、標準の短い形式の日付パターンは "M/d/yyyy" です。de 以外のカルチャでは、"dd" になります。MM. yyyy ";ja-jp カルチャでは、"yyyy/MM/dd" になります。For example, for the en-US culture, the standard short date pattern is "M/d/yyyy"; for the de-DE culture, it is "dd.MM.yyyy"; for the ja-JP culture, it is "yyyy/MM/dd". 値は、.NET の実装とそのバージョン、オペレーティングシステムとバージョン、およびユーザーのカスタマイズによって異なる場合があることに注意してください。Note that its value can vary depending on the .NET implementation and its version, the operating system and its version, and user customization.

現在のスレッド カルチャについて詳しくは、CultureInfo.CurrentCulture および Thread.CurrentCulture プロパティを参照してください。For more information about the current thread culture, see the CultureInfo.CurrentCulture and Thread.CurrentCulture properties. 書式指定文字、書式パターン、およびそれらによって生成される出力について詳しくは、「標準の日時書式指定文字列」と「カスタム日時書式指定文字列」をご覧ください。For more information about format characters, format patterns, and the output they produce, see Standard date and time format strings and Custom date and time format strings. 書式指定文字に関連付けられている書式パターンの変更について詳しくは、DateTimeFormatInfo クラスをご覧ください。For more information about changing the format pattern associated with a format character, see the DateTimeFormatInfo class.

適用対象

こちらもご覧ください