CultureInfo.DateTimeFormat CultureInfo.DateTimeFormat CultureInfo.DateTimeFormat CultureInfo.DateTimeFormat Property

Definición

Obtiene o establece un objeto DateTimeFormatInfo que define el formato de presentación de fechas y horas culturalmente apropiado.Gets or sets a DateTimeFormatInfo that defines the culturally appropriate format of displaying dates and times.

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

Valor de propiedad

DateTimeFormatInfo que define el formato de presentación de fechas y horas culturalmente apropiado.A DateTimeFormatInfo that defines the culturally appropriate format of displaying dates and times.

Excepciones

La propiedad se ha establecido en null.The property is set to null.

Se establece la propiedad DateTimeFormat o cualquiera de las propiedades DateTimeFormatInfo, y CultureInfo es de solo lectura.The DateTimeFormat property or any of the DateTimeFormatInfo properties is set, and the CultureInfo is read-only.

Ejemplos

En el ejemplo de código siguiente se muestra que CultureInfo. Clone también DateTimeFormatInfo clona NumberFormatInfo las instancias de y CultureInfoasociadas a.The following code example shows that CultureInfo.Clone also clones the DateTimeFormatInfo and NumberFormatInfo instances associated with the CultureInfo.

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

Comentarios

OverridesOverrides

El usuario puede optar por invalidar algunos de los valores asociados a la referencia cultural actual de Windows a través de la parte de opciones de idioma y configuración regional del panel de control.The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. Por ejemplo, el usuario podría elegir mostrar la fecha en un formato diferente o utilizar una moneda distinta de la predeterminada para la referencia cultural.For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture.

Si UseUserOverride CultureInfo es true y la referencia cultural especificada coincide con la referencia cultural actual de Windows, utiliza esas invalidaciones, incluida la configuración de usuario para DateTimeFormatInfo las propiedades de la DateTimeFormat instancia devuelta por la propiedad. y las propiedades de la NumberFormatInfo instancia devuelta por NumberFormat la propiedad.If UseUserOverride is true and the specified culture matches the current culture of Windows, the CultureInfo uses those overrides, including user settings for the properties of the DateTimeFormatInfo instance returned by the DateTimeFormat property, and the properties of the NumberFormatInfo instance returned by the NumberFormat property. Si la configuración del usuario es incompatible con la referencia cultural asociada CultureInfoa, por ejemplo, si el calendario seleccionado no es uno OptionalCalendarsde, los resultados de los métodos y los valores de las propiedades son indefinidos.If the user settings are incompatible with the culture associated with the CultureInfo, for example, if the selected calendar is not one of the OptionalCalendars, the results of the methods and the values of the properties are undefined.

El valor de la DateTimeFormat propiedad y la NumberFormat propiedad no se calculan hasta que la aplicación tenga acceso a la propiedad.The value of the DateTimeFormat property and the NumberFormat property is not calculated until your application accesses the property. Si el usuario puede cambiar la referencia cultural actual a una nueva referencia cultural mientras la aplicación se está ejecutando y, a continuación DateTimeFormat , NumberFormat la aplicación tiene acceso a la propiedad o, la aplicación recupera los valores predeterminados de la nueva referencia cultural en lugar de las invalidaciones para el referencia cultural original.If the user can change the current culture to a new culture while the application is running and then the application accesses the DateTimeFormat or NumberFormat property, the application retrieves the defaults for the new culture instead of the overrides for the original culture. Para conservar las invalidaciones de la referencia cultural actual original, la aplicación debe tener DateTimeFormat acceso NumberFormat a las propiedades y antes de cambiar la referencia cultural actual.To preserve the overrides for the original current culture, the application should access the DateTimeFormat and NumberFormat properties before changing the current culture.

Notas a los autores de las llamadas

Si Calendar GetEraName(Int32) GetAbbreviatedEraName(Int32) NativeCalendarNamees, peronoseestableceenChino(Taiwán),llamadozh-TW,entonces,ydevuelveunacadenavacía("").TaiwanCalendar CurrentCultureIf Calendar is the TaiwanCalendar but the CurrentCulture is not set to Chinese (Taiwan), named zh-TW, then NativeCalendarName, GetEraName(Int32), and GetAbbreviatedEraName(Int32) return an empty string ("").

Se aplica a

Consulte también: