DateTime.ToLongTimeString Yöntem

Tanım

Geçerli DateTime nesnenin değerini eşdeğer uzun süreli dize gösterimine dönüştürür.

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

Döndürülenler

String

Geçerli DateTime nesnenin uzun süreli dize gösterimini içeren bir dize.

Örnekler

Aşağıdaki örnekte yöntemi gösterilmektedir ToLongTimeString .

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
open System
open System.Threading
open System.Globalization

// Create a list of culture names.
let names = [ "en-US"; "en-GB"; "fr-FR"; "de-DE" ]

// Initialize a DateTime object.
let dateValue = DateTime(2013, 5, 28, 10, 30, 15)

// Iterate the array of culture names.
for name in names do
    // Change the culture of the current thread.
    Thread.CurrentThread.CurrentCulture <- CultureInfo.CreateSpecificCulture name
    // Display the name of the current culture and the date.
    printfn $"Current culture: {CultureInfo.CurrentCulture.Name}"
    printfn $"Date: {dateValue:G}"

    // Display the long time pattern and the long time.
    printfn $"Long time pattern: '{DateTimeFormatInfo.CurrentInfo.LongTimePattern}'"
    printfn $"Long time with format string:     {dateValue:T}"
    printfn $"Long time with ToLongTimeString:  {dateValue.ToLongTimeString()}\n"


// 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

Açıklamalar

Geçerli nesnenin değeri, geçerli DateTime kültürle ilişkili özellik tarafından DateTimeFormatInfo.LongTimePattern tanımlanan desen kullanılarak biçimlendirilir. Dönüş değeri, yöntemiyle "T" standart tarih ve saat biçim dizesi belirtilerek döndürülen değerle aynıdır ToString(String) .

Not

yöntemi tarafından ToLongTimeString döndürülen dize kültüre duyarlıdır. Geçerli kültürün DateTimeFormatInfo.LongTimePattern özelliği tarafından tanımlanan deseni yansıtır. Örneğin, en-US kültürü için standart uzun süreli desen "h:mm:ss tt"; de-DE kültürü için "SS:dd:ss"; ja-JP kültürü için "H:mm:ss" şeklindedir. Değerinin .NET uygulamasına ve sürümüne, işletim sistemine ve sürümüne ve kullanıcı özelleştirmesine bağlı olarak değişebileceğini unutmayın.

Geçerli iş parçacığı kültürü hakkında daha fazla bilgi için bkz CultureInfo.CurrentCulture . ve Thread.CurrentCulture özellikleri. Biçim karakterleri, biçim desenleri ve bunların ürettiği çıktı hakkında daha fazla bilgi için bkz. Standart Tarih ve saat biçimi dizeleri ve özel tarih ve saat biçimi dizeleri. Biçimlendirme karakteriyle ilişkili biçim deseninin değiştirilmesi hakkında daha fazla bilgi için, DateTimeFormatInfo sınıfına bakın.

Şunlara uygulanır

Ayrıca bkz.