CultureInfo.DateTimeFormat Eigenschaft

Definition

Ruft die DateTimeFormatInfo ab, die das für die Kultur spezifische Format zum Anzeigen von Datumsangaben und Uhrzeiten definiert, oder legt diese fest.

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

Eigenschaftswert

Eine DateTimeFormatInfo, die das für die Kultur spezifische Format zum Anzeigen von Datumsangaben und Uhrzeiten definiert.

Ausnahmen

Die Eigenschaft ist auf NULL festgelegt.

Die DateTimeFormat-Eigenschaft oder eine der DateTimeFormatInfo-Eigenschaften wird festgelegt, und die CultureInfo ist schreibgeschützt.

Beispiele

Das folgende Codebeispiel zeigt, dass CultureInfo.Clone auch die DateTimeFormatInfo Instanzen und NumberFormatInfo klont, die dem CultureInfozugeordnet sind.

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

Hinweise

Sie können einige der Werte, die der aktuellen Windows-Kultur zugeordnet sind, über den Teil der Regions- und Sprachoptionen von Systemsteuerung außer Kraft setzen. Beispielsweise kann der Benutzer das Datum in einem anderen Format anzeigen oder eine andere Währung als die Standardwährung für die Kultur verwenden.

Wenn UseUserOverride ist true und die angegebene Kultur mit der aktuellen Kultur von Windows übereinstimmt, verwendet diese CultureInfo Außerkraftsetzungen, einschließlich Benutzereinstellungen für die Eigenschaften der von der DateTimeFormatDateTimeFormatInfo -Eigenschaft zurückgegebenen instance und die Eigenschaften der von der NumberFormatInfoNumberFormat -Eigenschaft zurückgegebenen instance. Wenn die Benutzereinstellungen mit der kultur nicht kompatibel sind, die CultureInfozugeordnet ist, z. B. wenn der ausgewählte Kalender keiner der OptionalCalendarsist, sind die Ergebnisse der Methoden und die Werte der Eigenschaften nicht definiert.

Der Wert der DateTimeFormat Eigenschaft und der NumberFormat Eigenschaft wird erst berechnet, wenn Ihre Anwendung auf die Eigenschaft zugreift. Wenn der Benutzer die aktuelle Kultur während der Ausführung der Anwendung in eine neue Kultur ändern kann und die Anwendung dann auf die DateTimeFormat - oder NumberFormat -Eigenschaft zugreift, ruft die Anwendung die Standardwerte für die neue Kultur anstelle der Außerkraftsetzungen für die ursprüngliche Kultur ab. Um die Außerkraftsetzungen für die ursprüngliche aktuelle Kultur beizubehalten, sollte die Anwendung vor dem Ändern der aktuellen Kultur auf die DateTimeFormat Eigenschaften und NumberFormat zugreifen.

Hinweise für Aufrufer

Wenn Calendar ist, TaiwanCalendar aber nicht CurrentCulture auf Chinesisch (Taiwan) festgelegt ist, zh-TW, dann NativeCalendarName, GetEraName(Int32)und GetAbbreviatedEraName(Int32) gibt eine leere Zeichenfolge ("") zurück.

Gilt für:

Weitere Informationen