DateTime.ToLongTimeString 메서드

정의

현재 DateTime 개체의 값을 해당하는 긴 시간 문자열 표현으로 변환합니다.Converts the value of the current DateTime object to its equivalent long time string representation.

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

반환

현재 DateTime 개체의 긴 시간 문자열 표현을 포함하는 문자열입니다.A string that contains the long time string representation of the current DateTime object.

예제

다음 예제는 ToLongTimeString 메서드.The following example demonstrates the ToLongTimeString method.

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

설명

현재 DateTime 개체의 값은 현재 스레드 문화권과 연결 된 DateTimeFormatInfo.LongTimePattern 속성으로 정의 된 패턴을 사용 하 여 형식이 지정 됩니다.The value of the current DateTime object is formatted using the pattern defined by the DateTimeFormatInfo.LongTimePattern property associated with the current thread culture. 반환 값은 ToString(String) 메서드를 사용 하 여 "T" 표준 날짜 및 시간 형식 문자열 을 지정 하 여 반환 되는 값과 동일 합니다.The return value is identical to the value returned by specifying the "T" standard date and time format string with the ToString(String) method.

참고

ToLongTimeString 메서드에서 반환 되는 문자열은 문화권을 구분 합니다.The string returned by the ToLongTimeString method is culture-sensitive. 현재 문화권의 DateTimeFormatInfo.LongTimePattern 속성에 의해 정의 되는 패턴을 반영 합니다.It reflects the pattern defined by the current culture's DateTimeFormatInfo.LongTimePattern property. 예를 들어 EN-US 문화권에 대 한 표준 긴 시간 패턴은 "h:mm: ss tt"; DE-DE 문화권에 대 한 것이 "hh: mm:"; JA-JP 문화권 "h:mm: ss"입니다.For example, for the en-US culture, the standard long time pattern is "h:mm:ss tt"; for the de-DE culture, it is "HH:mm:ss"; for the ja-JP culture, it is "H:mm:ss". 해당 값은 .NET 구현과 해당 버전, 운영 체제 및 버전, 사용자 지정에 따라 달라질 수 있습니다.Note that its value can vary depending on the .NET implementation and its version, the operating system and its version, and user customization.

현재 스레드 문화권에 대한 자세한 내용은 CultureInfo.CurrentCultureThread.CurrentCulture 속성을 참조하세요.For more information about the current thread culture, see the CultureInfo.CurrentCulture and Thread.CurrentCulture properties. 형식 문자, 형식 패턴 및 해당 항목이 생성하는 출력에 대한 자세한 내용은 표준 날짜 및 시간 형식 문자열사용자 지정 날짜 및 시간 형식 문자열을 참조하세요.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. 형식 문자와 연결된 형식 패턴 변경에 대한 자세한 내용은 DateTimeFormatInfo 클래스를 참조하세요.For more information about changing the format pattern associated with a format character, see the DateTimeFormatInfo class.

적용 대상

추가 정보