C#의 DateTime.GetDateTimeFormats() 메서드는 이 인스턴스의 값을 표준 날짜 및 시간 형식 지정자가 지원하는 모든 문자열 표현으로 변환하는 데 사용됩니다.
구문
다음은 구문입니다 -
public string[] GetDateTimeFormats () public string[] GetDateTimeFormats (char ch);
위의 ch는 표준 날짜 및 시간 형식 문자열입니다.
예시
이제 DateTime.GetDateTimeFormats() 메서드를 구현하는 예를 살펴보겠습니다. -
using System; public class Demo { public static void Main() { DateTime d = new DateTime(2019, 11, 10, 7, 20, 45); string[] res = d.GetDateTimeFormats(); foreach(string s in res) Console.WriteLine(s); } }
출력
이것은 다음과 같은 출력을 생성합니다 -
11/10/2019 11/10/19 11/10/19 11/10/2019 19/11/10 2019-11-10 10-Nov-19 Sunday, November 10, 2019 November 10, 2019 Sunday, 10 November, 2019 10 November, 2019 Sunday, November 10, 2019 7:20 AM Sunday, November 10, 2019 07:20 AM Sunday, November 10, 2019 7:20 Sunday, November 10, 2019 07:20 November 10, 2019 7:20 AM November 10, 2019 07:20 AM November 10, 2019 7:20 November 10, 2019 07:20 Sunday, 10 November, 2019 7:20 AM Sunday, 10 November, 2019 07:20 AM Sunday, 10 November, 2019 7:20 Sunday, 10 November, 2019 07:20 10 November, 2019 7:20 AM 10 November, 2019 07:20 AM 10 November, 2019 7:20 10 November, 2019 07:20 Sunday, November 10, 2019 7:20:45 AM Sunday, November 10, 2019 07:20:45 AM Sunday, November 10, 2019 7:20:45 Sunday, November 10, 2019 07:20:45 November 10, 2019 7:20:45 AM November 10, 2019 07:20:45 AM November 10, 2019 7:20:45 November 10, 2019 07:20:45 Sunday, 10 November, 2019 7:20:45 AM Sunday, 10 November, 2019 07:20:45 AM Sunday, 10 November, 2019 7:20:45 Sunday, 10 November, 2019 07:20:45 10 November, 2019 7:20:45 AM 10 November, 2019 07:20:45 AM 10 November, 2019 7:20:45 10 November, 2019 07:20:45 11/10/2019 7:20 AM 11/10/2019 07:20 AM 11/10/2019 7:20 11/10/2019 07:20 11/10/19 7:20 AM 11/10/19 07:20 AM 11/10/19 7:20 11/10/19 07:20 11/10/19 7:20 AM 11/10/19 07:20 AM 11/10/19 7:20 11/10/19 07:20 11/10/2019 7:20 AM 11/10/2019 07:20 AM 11/10/2019 7:20 11/10/2019 07:20 19/11/10 7:20 AM 19/11/10 07:20 AM 19/11/10 7:20 19/11/10 07:20 2019-11-10 7:20 AM 2019-11-10 07:20 AM 2019-11-10 7:20 2019-11-10 07:20 10-Nov-19 7:20 AM 10-Nov-19 07:20 AM 10-Nov-19 7:20 10-Nov-19 07:20 11/10/2019 7:20:45 AM 11/10/2019 07:20:45 AM 11/10/2019 7:20:45 11/10/2019 07:20:45 11/10/19 7:20:45 AM 11/10/19 07:20:45 AM 11/10/19 7:20:45 11/10/19 07:20:45 11/10/19 7:20:45 AM 11/10/19 07:20:45 AM 11/10/19 7:20:45 11/10/19 07:20:45 11/10/2019 7:20:45 AM 11/10/2019 07:20:45 AM 11/10/2019 7:20:45 11/10/2019 07:20:45 19/11/10 7:20:45 AM 19/11/10 07:20:45 AM 19/11/10 7:20:45 19/11/10 07:20:45 2019-11-10 7:20:45 AM 2019-11-10 07:20:45 AM 2019-11-10 7:20:45 2019-11-10 07:20:45 10-Nov-19 7:20:45 AM 10-Nov-19 07:20:45 AM 10-Nov-19 7:20:45 10-Nov-19 07:20:45 November 10 November 10 2019-11-10T07:20:45.0000000 2019-11-10T07:20:45.0000000 Sun, 10 Nov 2019 07:20:45 GMT Sun, 10 Nov 2019 07:20:45 GMT 2019-11-10T07:20:45 7:20 AM 07:20 AM 7:20 07:20 7:20:45 AM 07:20:45 AM 7:20:45 07:20:45 2019-11-10 07:20:45Z Sunday, November 10, 2019 7:20:45 AM Sunday, November 10, 2019 07:20:45 AM Sunday, November 10, 2019 7:20:45 Sunday, November 10, 2019 07:20:45 November 10, 2019 7:20:45 AM November 10, 2019 07:20:45 AM November 10, 2019 7:20:45 November 10, 2019 07:20:45 Sunday, 10 November, 2019 7:20:45 AM Sunday, 10 November, 2019 07:20:45 AM Sunday, 10 November, 2019 7:20:45 Sunday, 10 November, 2019 07:20:45 10 November, 2019 7:20:45 AM 10 November, 2019 07:20:45 AM 10 November, 2019 7:20:45 10 November, 2019 07:20:45 November 2019 November 2019
예시
이제 DateTime.GetDateTimeFormats() 메서드를 구현하는 또 다른 예를 살펴보겠습니다. char 형식의 경우 짧은 날짜 패턴에 "d", 긴 날짜 패턴에 "D", 전체 날짜/시간 패턴에 "F"(긴 시간) 등과 같은 형식 지정자를 사용합니다.
using System; public class Demo { public static void Main() { DateTime d = new DateTime(2019, 11, 10, 7, 20, 45); string[] res = d.GetDateTimeFormats('F'); foreach(string s in res) Console.WriteLine(s); } }
출력
이것은 다음과 같은 출력을 생성합니다 -
Sunday, November 10, 2019 7:20:45 AM Sunday, November 10, 2019 07:20:45 AM Sunday, November 10, 2019 7:20:45 Sunday, November 10, 2019 07:20:45 November 10, 2019 7:20:45 AM November 10, 2019 07:20:45 AM November 10, 2019 7:20:45 November 10, 2019 07:20:45 Sunday, 10 November, 2019 7:20:45 AM Sunday, 10 November, 2019 07:20:45 AM Sunday, 10 November, 2019 7:20:45 Sunday, 10 November, 2019 07:20:45 10 November, 2019 7:20:45 AM 10 November, 2019 07:20:45 AM 10 November, 2019 7:20:45 10 November, 2019 07:20:45