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

Definición

Convierte el valor del objeto DateTime actual en su representación de cadena de fecha corta equivalente.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

Devoluciones

Una cadena que contiene la representación de cadena de fecha corta del objeto DateTime actual.A string that contains the short date string representation of the current DateTime object.

Ejemplos

En el ejemplo siguiente se muestra el ToShortDateString método.The following example demonstrates the ToShortDateString method. También muestra que el resultado de llamar a la ToShortDateString es idéntico a llamar al método el DateTime.ToString(String) método con "d" como el parámetro de formato.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

Comentarios

El valor del elemento actual DateTime objeto tiene el formato con el patrón definido por el DateTimeFormatInfo.ShortDatePattern propiedad asociada con la referencia cultural del subproceso actual.The value of the current DateTime object is formatted using the pattern defined by the DateTimeFormatInfo.ShortDatePattern property associated with the current thread culture. El valor devuelto es idéntico al valor devuelto mediante la especificación de la "d" cadena de formato de fecha y hora estándar con el ToString(String) método.The return value is identical to the value returned by specifying the "d" standard DateTime format string with the ToString(String) method.

Nota

La cadena devuelta por la ToShortDateString método es la referencia cultural.The string returned by the ToShortDateString method is culture-sensitive. Refleja el patrón definido por la referencia cultural actual DateTimeFormatInfo.ShortDatePattern propiedad.It reflects the pattern defined by the current culture's DateTimeFormatInfo.ShortDatePattern property. Por ejemplo, la referencia cultural en-US, el patrón de fecha corta estándar es "M/d/yyyy"; la referencia cultural de-DE, es "dd. MM.yyyy"; la referencia cultural ja-JP, es "aaaa/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". Tenga en cuenta que su valor puede variar dependiendo de la implementación de .NET y su versión, el sistema operativo y su versión y la personalización del usuario.Note that its value can vary depending on the .NET implementation and its version, the operating system and its version, and user customization.

Para obtener más información acerca de la referencia cultural del subproceso actual, vea las propiedades CultureInfo.CurrentCulture y Thread.CurrentCulture.For more information about the current thread culture, see the CultureInfo.CurrentCulture and Thread.CurrentCulture properties. Para obtener más información acerca de los caracteres de formato, modelos de formato y la salida que generan, consulte Cadenas con formato de fecha y hora estándar y Cadenas con formato de fecha y hora personalizado.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. Para obtener más información acerca de cómo cambiar el modelo de formato asociado a un carácter de formato, vea la clase DateTimeFormatInfo.For more information about changing the format pattern associated with a format character, see the DateTimeFormatInfo class.

Se aplica a

Consulte también: