DateTime.ToLongTimeString 메서드

정의

현재 DateTime 개체의 값을 해당하는 긴 시간 문자열 표현으로 변환합니다.

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

반환

String

현재 DateTime 개체의 긴 시간 문자열 표현을 포함하는 문자열입니다.

예제

다음 예제는 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

설명

현재 개체의 값은 현재 DateTime 문화권과 연결된 속성에 DateTimeFormatInfo.LongTimePattern 정의된 패턴을 사용하여 형식이 지정됩니다. 반환 값은 메서드를 사용하여 "T" 표준 날짜 및 시간 형식 문자열 을 지정하여 반환되는 ToString(String) 값과 동일합니다.

참고

메서드에서 반환된 ToLongTimeString 문자열은 문화권을 구분합니다. 현재 문화권의 DateTimeFormatInfo.LongTimePattern 속성에 의해 정의된 패턴을 반영합니다. 예를 들어 en-US 문화권의 경우 표준 Long Time 패턴은 "h:mm:ss tt"입니다. de-DE 문화권의 경우 "HH:mm:ss"입니다. ja-JP 문화권의 경우 "H:mm:ss"입니다. 해당 값은 .NET 구현 및 해당 버전, 운영 체제 및 해당 버전 및 사용자 사용자 지정에 따라 달라질 수 있습니다.

현재 스레드 문화권에 대한 자세한 내용은 CultureInfo.CurrentCultureThread.CurrentCulture 속성을 참조하세요. 형식 문자, 형식 패턴 및 해당 항목이 생성하는 출력에 대한 자세한 내용은 표준 날짜 및 시간 형식 문자열사용자 지정 날짜 및 시간 형식 문자열을 참조하세요. 형식 문자와 연결된 형식 패턴 변경에 대한 자세한 내용은 DateTimeFormatInfo 클래스를 참조하세요.

적용 대상

추가 정보