DateTimeFormatInfo.ShortDatePattern DateTimeFormatInfo.ShortDatePattern DateTimeFormatInfo.ShortDatePattern DateTimeFormatInfo.ShortDatePattern Property

定義

短い日付値のカスタム書式指定文字列を取得または設定します。Gets or sets the custom format string for a short date value.

public:
 property System::String ^ ShortDatePattern { System::String ^ get(); void set(System::String ^ value); };
public string ShortDatePattern { get; set; }
member this.ShortDatePattern : string with get, set
Public Property ShortDatePattern As String

プロパティ値

短い形式の日付の値のカスタム書式指定文字列。The custom format string for a short date value.

例外

プロパティが null に設定されています。The property is being set to null.

このプロパティが設定されていますが、DateTimeFormatInfo オブジェクトは読み取り専用です。The property is being set and the DateTimeFormatInfo object is read-only.

次の例の値を表示する、ShortDatePatternプロパティと値の日付の形式を使用して、ShortDatePatternいくつかのカルチャ プロパティ。The following example displays the value of the ShortDatePattern property and the value of a date formatted using the ShortDatePattern property for a few cultures.

using System;
using System.Globalization;
                                                                                               
public class SamplesDTFI  
{
   public static void Main()  
   {
      string[]  cultures = { "en-US", "ja-JP", "fr-FR" };
      DateTime date1 = new DateTime(2011, 5, 1);

      Console.WriteLine(" {0,7} {1,19} {2,10}\n", "CULTURE", "PROPERTY VALUE", "DATE");

      foreach (var culture in cultures) {
         DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture(culture).DateTimeFormat;
         Console.WriteLine(" {0,7} {1,19} {2,10}", culture, 
                           dtfi.ShortDatePattern, 
                           date1.ToString("d", dtfi));
      }
   }
}
// The example displays the following output:
//        CULTURE      PROPERTY VALUE       DATE
//       
//          en-US            M/d/yyyy   5/1/2011
//          ja-JP          yyyy/MM/dd 2011/05/01
//          fr-FR          dd/MM/yyyy 01/05/2011
Imports System.Globalization

Public Class SamplesDTFI
   Public Shared Sub Main()
      Dim cultures() As String = { "en-US", "ja-JP", "fr-FR" }
      Dim date1 As Date = #05/01/2011#
      
      Console.WriteLine(" {0,7} {1,19} {2,10}", "CULTURE", "PROPERTY VALUE", "DATE")
      Console.WriteLine()
      
      For Each culture As String In cultures
         Dim dtfi As DateTimeFormatInfo = CultureInfo.CreateSpecificCulture(culture).DateTimeFormat
         Console.WriteLine(" {0,7} {1,19} {2,10}", culture, 
                           dtfi.ShortDatePattern, 
                           date1.ToString("d", dtfi))
      Next                     
   End Sub 
End Class
' The example displays the following output:
'        CULTURE      PROPERTY VALUE       DATE
'       
'          en-US            M/d/yyyy   5/1/2011
'          ja-JP          yyyy/MM/dd 2011/05/01
'          fr-FR          dd/MM/yyyy 01/05/2011

次の例では、変更、ShortDatePatternのプロパティをDateTimeFormatInfo英語 (米国) カルチャの書式指定規則を表すオブジェクト。The following example modifies the ShortDatePattern property of a DateTimeFormatInfo object that represents the formatting conventions of the English (United States) culture. 表示されます、日付の値を 2 回は、まず元を反映するようにShortDatePatternプロパティをクリックし、新しいプロパティ値を反映するようにします。It also displays a date value twice, first to reflect the original ShortDatePattern property and then to reflect the new property value.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat;
      DateTime date1 = new DateTime(2011, 5, 1);
      Console.WriteLine("Original Short Date Pattern:");
      Console.WriteLine("   {0}: {1}", dtfi.ShortDatePattern, 
                                       date1.ToString("d", dtfi));
      dtfi.DateSeparator = "-";
      dtfi.ShortDatePattern = @"yyyy/MM/dd";
      Console.WriteLine("Revised Short Date Pattern:");
      Console.WriteLine("   {0}: {1}", dtfi.ShortDatePattern, 
                                       date1.ToString("d", dtfi));
   }
}
// The example displays the following output:
//       Original Short Date Pattern:
//          M/d/yyyy: 5/1/2011
//       Revised Short Date Pattern:
//          yyyy/MM/dd: 2011-05-01
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim dtfi As DateTimeFormatInfo = CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat
      Dim date1 As DateTime = #05/01/2011#
      Console.WriteLine("Original Short Date Pattern:")
      Console.WriteLine("   {0}: {1}", dtfi.ShortDatePattern, 
                                       date1.ToString("d", dtfi))
      dtfi.DateSeparator = "-"
      dtfi.ShortDatePattern = "yyyy/MM/dd"
      Console.WriteLine("Revised Short Date Pattern:")
      Console.WriteLine("   {0}: {1}", dtfi.ShortDatePattern, 
                                       date1.ToString("d", dtfi))
   End Sub
End Module
' The example displays the following output:
'    Original Short Date Pattern:
'       M/d/yyyy: 5/1/2011
'    Revised Short Date Pattern:
'       YYYY/MM/dd: 2011-05-01

注釈

ShortDatePatternプロパティへの呼び出しによって返される日付文字列のカルチャ固有の書式を定義する、DateTime.ToStringDateTimeOffset.ToStringメソッドによって複合書式指定文字列を使用するが、"d"標準書式指定文字列を指定するとします。The ShortDatePattern property defines the culture-specific format of date strings that are returned by calls to the DateTime.ToString and DateTimeOffset.ToString methods and by composite format strings that are supplied the "d" standard format string.

このプロパティは影響を受けた場合の値、Calendarプロパティの変更。This property is affected if the value of the Calendar property changes.

適用対象

こちらもご覧ください