생성 날짜 짧은 시간 형식 지정자는 공백으로 구분된 짧은 날짜("d") 및 짧은 시간("t") 패턴의 조합입니다.
DateTime을 사용하여 날짜를 설정합니다.
DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20);
이제 ("g") 형식 지정자를 사용합니다.
dt.ToString("g", DateTimeFormatInfo.InvariantInfo)); 예
using System;
using System.Globalization;
class Demo {
static void Main() {
DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20);
Console.WriteLine(dt.ToString("g", DateTimeFormatInfo.InvariantInfo));
Console.WriteLine(dt.ToString("g", CultureInfo.CreateSpecificCulture("en-us")));
}
} 출력
10/02/2018 07:59 10/2/2018 7:59 AM