CultureInfo.DateTimeFormat プロパティ

定義

カルチャに対応する、日時の表示形式を定義する DateTimeFormatInfo を取得または設定します。

public:
 virtual property System::Globalization::DateTimeFormatInfo ^ DateTimeFormat { System::Globalization::DateTimeFormatInfo ^ get(); void set(System::Globalization::DateTimeFormatInfo ^ value); };
public virtual System.Globalization.DateTimeFormatInfo DateTimeFormat { get; set; }
member this.DateTimeFormat : System.Globalization.DateTimeFormatInfo with get, set
Public Overridable Property DateTimeFormat As DateTimeFormatInfo

プロパティ値

カルチャに対応する、日時の表示形式を定義する DateTimeFormatInfo

例外

プロパティが null に設定されています。

DateTimeFormat プロパティまたは DateTimeFormatInfo プロパティのいずれかが設定され、CultureInfo は読み取り専用です。

次のコード例は、CultureInfo.Clone によって、 に関連付CultureInfoけられている インスタンスと NumberFormatInfo インスタンスも複製DateTimeFormatInfoされることを示しています。

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates and initializes a CultureInfo.
   CultureInfo^ myCI = gcnew CultureInfo( "en-US",false );
   
   // Clones myCI and modifies the DTFI and NFI instances associated with the clone.
   CultureInfo^ myCIclone = dynamic_cast<CultureInfo^>(myCI->Clone());
   myCIclone->DateTimeFormat->AMDesignator = "a.m.";
   myCIclone->DateTimeFormat->DateSeparator = "-";
   myCIclone->NumberFormat->CurrencySymbol = "USD";
   myCIclone->NumberFormat->NumberDecimalDigits = 4;
   
   // Displays the properties of the DTFI and NFI instances associated with the original and with the clone. 
   Console::WriteLine( "DTFI/NFI PROPERTY\tORIGINAL\tMODIFIED CLONE" );
   Console::WriteLine( "DTFI.AMDesignator\t{0}\t\t{1}", myCI->DateTimeFormat->AMDesignator, myCIclone->DateTimeFormat->AMDesignator );
   Console::WriteLine( "DTFI.DateSeparator\t{0}\t\t{1}", myCI->DateTimeFormat->DateSeparator, myCIclone->DateTimeFormat->DateSeparator );
   Console::WriteLine( "NFI.CurrencySymbol\t{0}\t\t{1}", myCI->NumberFormat->CurrencySymbol, myCIclone->NumberFormat->CurrencySymbol );
   Console::WriteLine( "NFI.NumberDecimalDigits\t{0}\t\t{1}", myCI->NumberFormat->NumberDecimalDigits, myCIclone->NumberFormat->NumberDecimalDigits );
}

/*
This code produces the following output.

DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
DTFI.AMDesignator       AM              a.m.
DTFI.DateSeparator      /               -
NFI.CurrencySymbol      $               USD
NFI.NumberDecimalDigits 2               4
*/
using System;
using System.Globalization;

public class SamplesCultureInfo  {

   public static void Main()  {

      // Creates and initializes a CultureInfo.
      CultureInfo myCI = new CultureInfo("en-US", false);

      // Clones myCI and modifies the DTFI and NFI instances associated with the clone.
      CultureInfo myCIclone = (CultureInfo) myCI.Clone();
      myCIclone.DateTimeFormat.AMDesignator = "a.m.";
      myCIclone.DateTimeFormat.DateSeparator = "-";
      myCIclone.NumberFormat.CurrencySymbol = "USD";
      myCIclone.NumberFormat.NumberDecimalDigits = 4;

      // Displays the properties of the DTFI and NFI instances associated with the original and with the clone.
      Console.WriteLine( "DTFI/NFI PROPERTY\tORIGINAL\tMODIFIED CLONE" );
      Console.WriteLine( "DTFI.AMDesignator\t{0}\t\t{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator );
      Console.WriteLine( "DTFI.DateSeparator\t{0}\t\t{1}", myCI.DateTimeFormat.DateSeparator, myCIclone.DateTimeFormat.DateSeparator );
      Console.WriteLine( "NFI.CurrencySymbol\t{0}\t\t{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol );
      Console.WriteLine( "NFI.NumberDecimalDigits\t{0}\t\t{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits );
   }
}

/*
This code produces the following output.

DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
DTFI.AMDesignator       AM              a.m.
DTFI.DateSeparator      /               -
NFI.CurrencySymbol      $               USD
NFI.NumberDecimalDigits 2               4

*/
Imports System.Globalization


Public Class SamplesCultureInfo
   
   Public Shared Sub Main()
      
      ' Creates and initializes a CultureInfo.
      Dim myCI As New CultureInfo("en-US", False)
      
      ' Clones myCI and modifies the DTFI and NFI instances associated with the clone.
      Dim myCIclone As CultureInfo = CType(myCI.Clone(), CultureInfo)
      myCIclone.DateTimeFormat.AMDesignator = "a.m."
      myCIclone.DateTimeFormat.DateSeparator = "-"
      myCIclone.NumberFormat.CurrencySymbol = "USD"
      myCIclone.NumberFormat.NumberDecimalDigits = 4
      
      ' Displays the properties of the DTFI and NFI instances associated with the original and with the clone. 
      Console.WriteLine("DTFI/NFI PROPERTY" + ControlChars.Tab + "ORIGINAL" + ControlChars.Tab + "MODIFIED CLONE")
      Console.WriteLine("DTFI.AMDesignator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator)
      Console.WriteLine("DTFI.DateSeparator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.DateSeparator, myCIclone.DateTimeFormat.DateSeparator)
      Console.WriteLine("NFI.CurrencySymbol" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol)
      Console.WriteLine("NFI.NumberDecimalDigits" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits)

   End Sub

End Class


' This code produces the following output.
'
' DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
' DTFI.AMDesignator       AM              a.m.
' DTFI.DateSeparator      /               -
' NFI.CurrencySymbol      $               USD
' NFI.NumberDecimalDigits 2               4

注釈

windows の現在のカルチャに関連付けられている値の一部を、コントロール パネルの地域と言語のオプションの部分を使用してオーバーライドすることもできます。 たとえば、ユーザーは日付を別の形式で表示するか、カルチャの既定値以外の通貨を使用するかを選択できます。

true で、指定したカルチャが Windows の現在のカルチャと一致する場合UseUserOverrideCultureInfo では、プロパティによって返されるインスタンスのDateTimeFormatInfoプロパティのユーザー設定や、 プロパティによってDateTimeFormat返されるインスタンスのNumberFormatInfoプロパティなど、これらのオーバーライドがNumberFormat使用されます。 ユーザー設定が に関連付けられている CultureInfoカルチャと互換性がない場合 (たとえば、選択した予定表が の OptionalCalendars1 つではない場合)、メソッドの結果とプロパティの値は未定義です。

プロパティと NumberFormat プロパティのDateTimeFormat値は、アプリケーションが プロパティにアクセスするまで計算されません。 アプリケーションの実行中にユーザーが現在のカルチャを新しいカルチャに変更し、アプリケーションが または NumberFormat プロパティにアクセスDateTimeFormatできる場合、アプリケーションは元のカルチャのオーバーライドではなく、新しいカルチャの既定値を取得します。 元の現在のカルチャのオーバーライドを保持するには、現在のカルチャを変更する前に、 プロパティと NumberFormat プロパティにアクセスDateTimeFormatする必要があります。

注意 (呼び出し元)

が ですが、 TaiwanCalendarCurrentCulture が中国語 (台湾) に設定されていない場合Calendarは、zh-TW という名前で 、、NativeCalendarNameGetEraName(Int32)GetAbbreviatedEraName(Int32)の文字列 ("") が返されます。

適用対象

こちらもご覧ください