DateTime.ToLongDateString Método

Definição

Converte o valor do atual objeto DateTime na representação de cadeia de caracteres de data completa equivalente.Converts the value of the current DateTime object to its equivalent long date string representation.

public:
 System::String ^ ToLongDateString();
public string ToLongDateString ();
member this.ToLongDateString : unit -> string
Public Function ToLongDateString () As String

Retornos

Uma cadeia de caracteres que contém a representação de cadeia de caracteres de data completa do atual objeto DateTime.A string that contains the long date string representation of the current DateTime object.

Exemplos

O exemplo a seguir demonstra o método ToLongDateString.The following example demonstrates the ToLongDateString method.

using System;
using System.Globalization;

class Sample 
{
    public static void Main() 
    {
        // Initialize a DateTime object.
        Console.WriteLine("Initialize the DateTime object to May 16, 2001 3:02:15 AM.\n");
        DateTime dateAndTime = new System.DateTime(2001, 5, 16, 3, 2, 15);

        // Display the name of the current culture.
        Console.WriteLine($"Current culture: \"{CultureInfo.CurrentCulture.Name}\"\n");
        var dtfi = CultureInfo.CurrentCulture.DateTimeFormat;

        // Display the long date pattern and string.
        Console.WriteLine($"Long date pattern: \"{dtfi.LongDatePattern}\"");
        Console.WriteLine($"Long date string:  \"{dateAndTime.ToLongDateString()}\"\n");

        // Display the long time pattern and string.
        Console.WriteLine($"Long time pattern: \"{dtfi.LongTimePattern}\"");
        Console.WriteLine($"Long time string:  \"{dateAndTime.ToLongTimeString()}\"\n");

        // Display the short date pattern and string.
        Console.WriteLine($"Short date pattern: \"{dtfi.ShortDatePattern}\"");
        Console.WriteLine($"Short date string:  \"{dateAndTime.ToShortDateString()}\"\n");

        // Display the short time pattern and string.
        Console.WriteLine($"Short time pattern: \"{dtfi.ShortTimePattern}\"");
        Console.WriteLine($"Short time string:  \"{dateAndTime.ToShortTimeString()}\"\n");
    }
}
// The example displays output similar to the following:
//        Current culture: "en-US"
//
//        Long date pattern: "dddd, MMMM d, yyyy"
//        Long date string:  "Wednesday, May 16, 2001"
//
//        Long time pattern: "h:mm:ss tt"
//        Long time string:  "3:02:15 AM"
//
//        Short date pattern: "M/d/yyyy"
//        Short date string:  "5/16/2001"
//
//        Short time pattern: "h:mm tt"
//        Short time string:  "3:02 AM"
Imports System.Globalization

Module Example
    Public Sub Main() 
        ' Initialize a DateTime object.
        Console.WriteLine($"Initialize the DateTime object to May 16, 2001 3:02:15 AM.{vbCrLf}")
        Dim dateAndTime As New DateTime(2001, 5, 16, 3, 2, 15)
        
        ' Display the name of the current culture.
        Console.WriteLine($"Current culture: ""{CultureInfo.CurrentCulture.Name}""{vbCrLf}")
        Dim dtfi = CultureInfo.CurrentCulture.DateTimeFormat
        
        ' Display the long date pattern and string.
        Console.WriteLine($"Long date pattern: ""{dtfi.LongDatePattern}""")
        Console.WriteLine($"Long date string:  ""{dateAndTime.ToLongDateString()}{vbCrLf}")
        
        ' Display the long time pattern and string.
        Console.WriteLine($"Long time pattern: ""{0}""", dtfi.LongTimePattern)
        Console.WriteLine($"Long time string:  ""{dateAndTime.ToLongTimeString()}{vbCrLf}")
        
        ' Display the short date pattern and string.
        Console.WriteLine($"Short date pattern: ""{dtfi.ShortDatePattern}""")
        Console.WriteLine($"Short date string:  ""{dateAndTime.ToShortDateString()}{vbCrLf}")
        
        ' Display the short time pattern and string.
        Console.WriteLine($"Short time pattern: ""{dtfi.ShortTimePattern}""")
        Console.WriteLine($"Short time string:  ""{dateAndTime.ToShortTimeString()}{vbCrLf}")
    End Sub
End Module
' The example displays output like the following:
'       Initialize the DateTime object to May 16, 2001 3:02:15 AM.
'
'       Current culture: "en-US"
'
'       Long date pattern: "dddd, MMMM d, yyyy"
'       Long date string:  "Wednesday, May 16, 2001
'
'       Long time pattern: "0"
'       Long time string:  "3:02:15 AM
'
'       Short date pattern: "M/d/yyyy"
'       Short date string:  "5/16/2001
'
'       Short time pattern: "h:mm tt"
'       Short time string:  "3:02 AM

Comentários

O valor do objeto de DateTime atual é formatado usando o padrão definido pela propriedade LongDatePattern associada à cultura de thread atual.The value of the current DateTime object is formatted using the pattern defined by the LongDatePattern property associated with the current thread culture. O valor de retorno é idêntico ao valor retornado pela especificação da cadeia de caracteres de formato DateTime padrão "D" com o método ToString(String).The return value is identical to the value returned by specifying the "D" standard DateTime format string with the ToString(String) method.

Observação

A cadeia de caracteres retornada pelo método de ToLongDateString é sensível à cultura.The string returned by the ToLongDateString method is culture-sensitive. Ele reflete o padrão definido pela propriedade de DateTimeFormatInfo.LongDatePattern da cultura atual.It reflects the pattern defined by the current culture's DateTimeFormatInfo.LongDatePattern property. Por exemplo, para a cultura en-US, o padrão de data por extenso padrão é normalmente "dddd, MMMM dd, yyyy"; para a cultura de-DE, é "dddd, d.For example, for the en-US culture, the standard long date pattern is commonly "dddd, MMMM dd, yyyy"; for the de-DE culture, it is "dddd, d. MMMM aaaa "; para a cultura ja-JP, é "yyyy ' 年 ' 月 ' 日 '".MMMM yyyy"; for the ja-JP culture, it is "yyyy'年'M'月'd'日'". Observe que seu valor pode variar dependendo da implementação do .NET e de sua versão, do sistema operacional e de sua versão e da personalização do usuário.Note that its value can vary depending on the .NET implementation and its version, the operating system and its version, and user customization.

Para obter mais informações sobre a cultura do thread atual, confira as propriedades CultureInfo.CurrentCulture e Thread.CurrentCulture.For more information about the current thread culture, see the CultureInfo.CurrentCulture and Thread.CurrentCulture properties. Para obter mais informações sobre caracteres, padrões de formatos e a saída que eles produzem, confira Cadeias de caracteres de formato padrão de data e hora e Cadeias de caracteres de formato personalizado de data e hora.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 obter mais informações sobre como alterar o padrão de formato associado a um caractere de formato, consulte a classe DateTimeFormatInfo.For more information about changing the format pattern associated with a format character, see the DateTimeFormatInfo class.

Aplica-se a

Veja também