DateTime.ToLongTimeString Methode

Definition

Konvertiert den Wert des aktuellen DateTime-Objekts in die entsprechende Zeichenfolgendarstellung im langen Zeitformat.

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

Gibt zurück

String

Eine Zeichenfolge, die eine Darstellung des aktuellen DateTime-Objekts im langen Zeitformat enthält.

Beispiele

Das folgende Beispiel veranschaulicht die ToLongTimeString Methode.

using System;
using System.Threading;
using System.Globalization;

public class Sample
{
   public static void Main()
   {
      // Create an array of culture names.
      String[] names = { "en-US", "en-GB", "fr-FR", "de-DE" };
      // Initialize a DateTime object.
      DateTime dateValue = new System.DateTime(2013, 5, 28, 10, 30, 15);

      // Iterate the array of culture names.
      foreach (var name in names) {
         // Change the culture of the current thread.
         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(name);
         // Display the name of the current culture and the date.
         Console.WriteLine("Current culture: {0}", CultureInfo.CurrentCulture.Name);
         Console.WriteLine("Date: {0:G}", dateValue);

         // Display the long time pattern and the long time.
         Console.WriteLine("Long time pattern: '{0}'",
                           DateTimeFormatInfo.CurrentInfo.LongTimePattern);
         Console.WriteLine("Long time with format string:     {0:T}", dateValue);
         Console.WriteLine("Long time with ToLongTimeString:  {0}\n",
                           dateValue.ToLongTimeString());
      }
   }
}
// The example displays the following output:
//       Current culture: en-US
//       Date: 5/28/2013 10:30:15 AM
//       Long time pattern: 'h:mm:ss tt'
//       Long time with format string:     10:30:15 AM
//       Long time with ToLongTimeString:  10:30:15 AM
//
//       Current culture: en-GB
//       Date: 28/05/2013 10:30:15
//       Long time pattern: 'HH:mm:ss'
//       Long time with format string:     10:30:15
//       Long time with ToLongTimeString:  10:30:15
//
//       Current culture: fr-FR
//       Date: 28/05/2013 10:30:15
//       Long time pattern: 'HH:mm:ss'
//       Long time with format string:     10:30:15
//       Long time with ToLongTimeString:  10:30:15
//
//       Current culture: de-DE
//       Date: 28.05.2013 10:30:15
//       Long time pattern: 'HH:mm:ss'
//       Long time with format string:     10:30:15
//       Long time with ToLongTimeString:  10:30:15
Imports System.Threading
Imports System.Globalization

Public Class Example
   Public Shared Sub Main() 
      ' Create an array of culture names.
      Dim names() As String = { "en-US", "en-GB", "fr-FR", "de-DE" }
      ' Initialize a DateTime object.
      Dim dateValue As New DateTime(2013, 5, 28, 10, 30, 15)
        
      ' Iterate the array of culture names.
      For Each name In names
         ' Change the culture of the current thread.
         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(name)
         ' Display the name of the current culture and the date.
         Console.WriteLine("Current culture: {0}", CultureInfo.CurrentCulture.Name)
         Console.WriteLine("Date: {0:G}", dateValue)        

         ' Display the long time pattern and the long time.
         Console.WriteLine("Long time pattern: '{0}'", DateTimeFormatInfo.CurrentInfo.LongTimePattern)
         Console.WriteLine("Long time with format string:     {0:T}", dateValue)
         Console.WriteLine("Long time with ToLongTimeString:  {0}", dateValue.ToLongTimeString())
         Console.WriteLine()
      Next
   End Sub 
End Class 
' The example displays the following output:
'       Current culture: en-US
'       Date: 5/28/2013 10:30:15 AM
'       Long time pattern: 'h:mm:ss tt'
'       Long time with format string:     10:30:15 AM
'       Long time with ToLongTimeString:  10:30:15 AM
'       
'       Current culture: en-GB
'       Date: 28/05/2013 10:30:15
'       Long time pattern: 'HH:mm:ss'
'       Long time with format string:     10:30:15
'       Long time with ToLongTimeString:  10:30:15
'       
'       Current culture: fr-FR
'       Date: 28/05/2013 10:30:15
'       Long time pattern: 'HH:mm:ss'
'       Long time with format string:     10:30:15
'       Long time with ToLongTimeString:  10:30:15
'       
'       Current culture: de-DE
'       Date: 28.05.2013 10:30:15
'       Long time pattern: 'HH:mm:ss'
'       Long time with format string:     10:30:15
'       Long time with ToLongTimeString:  10:30:15

Hinweise

Der Wert des aktuellen DateTime -Objekts wird mithilfe des Musters formatiert, das durch die -Eigenschaft definiert wird, DateTimeFormatInfo.LongTimePattern die der aktuellen Kultur zugeordnet ist. Der Rückgabewert ist mit dem zurückgegebenen Wert identisch, indem die Standardformatzeichenfolge für Datum und Uhrzeit "T" mit der -Methode angegeben ToString(String) wird.

Hinweis

Die von der -Methode zurückgegebene Zeichenfolge ToLongTimeString ist kulturabhängig. Es spiegelt das Muster wider, das durch die -Eigenschaft der aktuellen Kultur definiert DateTimeFormatInfo.LongTimePattern wird. Für die Kultur "en-US" lautet das Standardmuster für lange Zeit beispielsweise "h:mm:ss tt"; für die De-DE-Kultur ist dies "HH:mm:ss"; für die ja-JP-Kultur ist dies "H:mm:ss". Beachten Sie, dass der Wert je nach .NET-Implementierung, Version, Betriebssystem und Version sowie Benutzeranpassung variieren kann.

Weitere Informationen zur aktuellen Threadkultur finden Sie in den Eigenschaften CultureInfo.CurrentCulture und Thread.CurrentCulture. Weiter Informationen zu Formatzeichenfolgen, Formatmustern und zu der von ihnen generierten Ausgabe finden Sie unter Standardformatzeichenfolgen für Datum und Uhrzeit und Benutzerdefinierte Formatzeichenfolgen für Datum und Uhrzeit. Weitere Informationen zum Ändern des einem Formatzeichen zugeordneten Formatmusters finden Sie in der DateTimeFormatInfo-Klasse.

Gilt für

Siehe auch