DateTime.ToLongDateString Méthode

Définition

Convertit la valeur de l'objet DateTime actuel en sa représentation sous forme de chaîne de date longue équivalente.

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

Retours

Chaîne qui contient la représentation sous forme de chaîne de date longue de l'objet DateTime actuel.

Exemples

L’exemple suivant illustre la ToLongDateString méthode.

open System
open System.Globalization

// Initialize a DateTime object.
printfn "Initialize the DateTime object to May 16, 2001 3:02:15 AM.\n"
let dateAndTime = DateTime(2001, 5, 16, 3, 2, 15)

// Display the name of the current culture.
printfn $"Current culture: \"{CultureInfo.CurrentCulture.Name}\"\n"
let dtfi = CultureInfo.CurrentCulture.DateTimeFormat

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

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

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

// Display the short time pattern and string.
printfn $"Short time pattern: \"{dtfi.ShortTimePattern}\""
printfn $"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"
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

Remarques

La valeur de l’objet actuel DateTime est mise en forme à l’aide du modèle défini par la LongDatePattern propriété associée à la culture actuelle. La valeur de retour est identique à la valeur retournée en spécifiant la chaîne de format DateTime standard « D » avec la ToString(String) méthode .

Notes

La chaîne retournée par la méthode est sensible à la ToLongDateString culture. Elle reflète le modèle défini par la propriété de DateTimeFormatInfo.LongDatePattern la culture actuelle. Par exemple, pour la culture en-US, le modèle de date longue standard est généralement « dddd, MMMM jj, aaaa » ; pour la culture de de-DE, c’est « dddd, d. MMMM aaaa »; pour la culture ja-JP, c’est « aaaa’年’M’月’d’日' ». Notez que sa valeur peut varier en fonction de l’implémentation de .NET et de sa version, du système d’exploitation et de sa version, ainsi que de la personnalisation de l’utilisateur.

Pour en savoir plus sur la culture actuelle du thread, consultez les propriétés CultureInfo.CurrentCulture et Thread.CurrentCulture. Pour en savoir plus sur les caractères de format, les modèles de format et la sortie qu’ils produisent, voir Chaînes de format de date et d’heure standard et Chaînes de format de date et d’heure personnalisées. Pour en savoir plus sur la modification du modèle de format associé à un caractère de format, consultez la classe DateTimeFormatInfo.

S’applique à

Voir aussi