DateTime.ToShortTimeString 메서드

정의

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

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

반환

String

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

예제

다음 예제는 ToShortTimeString 메서드.

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

설명

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

참고

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

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

적용 대상

추가 정보