DateTime.ToShortDateString DateTime.ToShortDateString DateTime.ToShortDateString DateTime.ToShortDateString Method

定義

現在の 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メソッドを呼び出すことと同じ、DateTime.ToString(String)形式のパラメーターとして"d"を持つメソッド。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. 戻り値は"d"を指定することによって返される値と同じ標準日時書式指定文字列で、ToString(String)メソッド。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-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.

適用対象

こちらもご覧ください