다음을 통해 공유


DateTimeFormatInfo 클래스

Culture에 따라 DateTime 값의 형식이 지정되고 표시되는 방법을 정의합니다.

네임스페이스: System.Globalization
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class DateTimeFormatInfo
    Implements ICloneable, IFormatProvider
‘사용 방법
Dim instance As DateTimeFormatInfo
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class DateTimeFormatInfo sealed : ICloneable, IFormatProvider
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class DateTimeFormatInfo implements ICloneable, IFormatProvider
SerializableAttribute 
ComVisibleAttribute(true) 
public final class DateTimeFormatInfo implements ICloneable, IFormatProvider

설명

이 클래스에는 날짜 패턴, 시간 패턴 및 AM/PM 지정자와 같은 정보가 들어 있습니다.

특정 culture에 대한 DateTimeFormatInfo를 만들려면 해당 culture에 대한 CultureInfo를 만든 다음 CultureInfo.DateTimeFormat 속성을 검색합니다. 현재 스레드의 culture에 대한 DateTimeFormatInfo를 만들려면 CurrentInfo 속성을 사용합니다. 불변 culture에 대한 DateTimeFormatInfo를 만들려면 읽기 전용 버전의 InvariantInfo 속성을 사용하거나 쓰기 가능한 버전의 DateTimeFormatInfo 생성자를 사용합니다. 중립 culture에 대한 DateTimeFormatInfo를 만들 수 없습니다.

사용자는 제어판의 국가별 설정 옵션을 사용하여 Windows의 현재 culture와 관련된 일부 값을 재정의할 수 있습니다. 예를 들어, 날짜를 다른 형식으로 표시하거나 해당 culture의 기본 통화 단위가 아닌 다른 통화 단위를 사용할 수 있습니다. CultureInfo.UseUserOverride 속성을 true로 설정한 경우 CultureInfo.DateTimeFormat 인스턴스, CultureInfo.NumberFormat 인스턴스 및 CultureInfo.TextInfo 인스턴스의 속성 또한 사용자 설정에서 검색됩니다. 사용자 설정이 CultureInfo에 연결된 culture와 호환되지 않는 경우(예: 선택한 달력이 OptionalCalendars 중 하나가 아닌 경우) 해당 메서드의 결과와 속성 값은 정의되지 않습니다.

DateTime 값의 형식은 DateTimeFormatInfo 속성에 저장된 표준 또는 사용자 지정 패턴을 사용하여 지정됩니다.

쓰기 가능한 DateTimeFormatInfo의 관련 속성을 설정하여 표준 패턴을 사용자 지정 패턴으로 대체할 수 있습니다. DateTimeFormatInfo에 쓸 수 있는지 확인하려면 IsReadOnly 속성을 사용합니다.

다음 표에서는 각 표준 패턴과 표준 패턴을 수정하기 위해 설정할 수 있는 관련 DateTimeFormatInfo 속성에 대한 표준 서식 문자를 보여 줍니다. 이러한 형식 문자는 대/소문자를 구분합니다. 예를 들어, 'g'와 'G'는 약간 다른 패턴을 나타냅니다.

형식 문자

관련 속성/설명

d

ShortDatePattern

D

LongDatePattern

f

전체 날짜 및 시간(자세한 날짜와 간단한 시간)

F

FullDateTimePattern(자세한 날짜와 자세한 시간)

g

일반(간단한 날짜와 간단한 시간)

G

일반(간단한 날짜와 자세한 시간)

m, M

MonthDayPattern

r, R

RFC1123Pattern

s

지역 시간을 사용한 SortableDateTimePattern(ISO 8601 기반)

t

ShortTimePattern

T

LongTimePattern

u

세계 표준시 표시 형식을 사용한 UniversalSortableDateTimePattern

U

지역 표준시를 사용한 전체 날짜 및 시간(자세한 날짜와 자세한 시간)

y, Y

YearMonthPattern

다음 표에서는 조합하여 사용자 지정 패턴을 생성할 수 있는 패턴을 보여 줍니다. 이러한 패턴은 대/소문자를 구분합니다. 예를 들어, "MM"은 사용할 수 있지만 "mm"은 사용할 수 없습니다. 사용자 지정 패턴에 공백 문자나 작은따옴표(')로 둘러싸인 문자가 들어 있으면 출력 문자열에 해당 문자가 포함됩니다. 형식 패턴의 일부나 형식 문자로 정의되지 않은 문자는 그대로 나타납니다.

형식 패턴

설명

d, %d

날짜. 숫자 하나인 일자에는 앞에 0이 붙지 않습니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%d"를 지정합니다.

dd

날짜. 숫자 하나인 일자에는 앞에 0이 붙습니다.

ddd

AbbreviatedDayNames에 정의된 약식 요일 이름

dddd

DayNames에 정의된 자세한 요일 이름

M, %M

숫자로 표현된 월. 숫자 하나인 월에는 앞에 0이 붙지 않습니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%M"을 지정합니다.

MM

숫자로 표현된 월. 숫자 하나인 월에는 앞에 0이 붙습니다.

MMM

AbbreviatedMonthNames에 정의된 약식 월 이름

MMMM

MonthNames에 정의된 자세한 월 이름

y, %y

세기 표시 제외 연도. 세기 부분을 제외한 연도가 10보다 작은 경우 연도 앞에 0이 붙지 않습니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%y"를 지정합니다.

yy

세기 표시 제외 연도. 세기 부분을 제외한 연도가 10보다 작은 경우 연도 앞에 0이 붙습니다.

yyyy

세기를 포함한 네 자리 숫자 연도

gg

서기. 형식이 지정될 날짜에 연관된 서기 문자열이 없는 경우 이 패턴은 무시됩니다.

h, %h

12시간제 시간. 숫자 하나인 시간에는 앞에 0이 붙지 않습니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%h"를 지정합니다.

hh

12시간제 시간. 숫자 하나인 시간에는 앞에 0이 붙습니다.

H, %H

24시간제 시간. 숫자 하나인 시간에는 앞에 0이 붙지 않습니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%H"를 지정합니다.

HH

24시간제 시간. 숫자 하나인 시간에는 앞에 0이 붙습니다.

m, %m

분. 숫자 하나인 분에는 앞에 0이 붙지 않습니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%m"을 지정합니다.

mm

분. 숫자 하나인 분에는 앞에 0이 붙습니다.

s, %s

초. 숫자 하나인 초에는 앞에 0이 붙지 않습니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%s"를 지정합니다.

ss

초. 숫자 하나인 초에는 앞에 0이 붙습니다.

f, %f

한 자리 정밀도에서 초의 소수 부분입니다. 나머지 자릿수는 잘립니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%f"를 지정합니다.

ff

두 자리 정밀도에서 초의 소수 부분입니다. 나머지 자릿수는 잘립니다.

fff

세 자리 정밀도에서 초의 소수 부분입니다. 나머지 자릿수는 잘립니다.

ffff

네 자리 정밀도에서 초의 소수 부분입니다. 나머지 자릿수는 잘립니다.

fffff

다섯 자리 정밀도에서 초의 소수 부분입니다. 나머지 자릿수는 잘립니다.

ffffff

여섯 자리 정밀도에서 초의 소수 부분입니다. 나머지 자릿수는 잘립니다.

fffffff

일곱 자리 정밀도에서 초의 소수 부분입니다. 나머지 자릿수는 잘립니다.

F, %F

초의 소수 부분에 대한 최대 유효 자릿수를 표시합니다. 이 자릿수가 0이면 아무 것도 표시되지 않습니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%F"를 지정합니다.

FF

초의 소수 부분에 대한 최대 유효 자릿수를 2개로 표시합니다. 그러나 후행 0이나 2개의 0으로 된 숫자는 표시되지 않습니다.

FFF

초의 소수 부분에 대한 최대 유효 자릿수를 3개로 표시합니다. 그러나 후행 0이나 3개의 0으로 된 숫자는 표시되지 않습니다.

FFFF

초의 소수 부분에 대한 최대 유효 자릿수를 4개로 표시합니다. 그러나 후행 0이나 4개의 0으로 된 숫자는 표시되지 않습니다.

FFFFF

초의 소수 부분에 대한 최대 유효 자릿수를 5개로 표시합니다. 그러나 후행 0이나 5개의 0으로 된 숫자는 표시되지 않습니다.

FFFFFF

초의 소수 부분에 대한 최대 유효 자릿수를 6개로 표시합니다. 그러나 후행 0이나 6개의 0으로 된 숫자는 표시되지 않습니다.

FFFFFFF

초의 소수 부분에 대한 최대 유효 자릿수를 7개로 표시합니다. 그러나 후행 0이나 7개의 0으로 된 숫자는 표시되지 않습니다.

t, %t

AMDesignator 또는 PMDesignator에 정의된 AM/PM 지정자의 첫 문자입니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%t"를 지정합니다.

tt

AMDesignator 또는 PMDesignator에 정의된 AM/PM 지정자입니다.

z, %z

시간대 오프셋("+" 또는 "-" 뒤에 시간만 옴)입니다. 숫자 하나인 시간에는 앞에 0이 붙지 않습니다. 예를 들어, 태평양 표준시는 "-8"입니다. 형식 패턴이 다른 형식 패턴과 결합되지 않을 경우 "%z"를 지정합니다.

zz

시간대 오프셋("+" 또는 "-" 뒤에 시간만 옴)입니다. 숫자 하나인 시간에는 앞에 0이 붙습니다. 예를 들어, 태평양 표준시는 "-08"입니다.

zzz

자세한 시간대 오프셋("+" 또는 "-" 뒤에 시간과 분이 옴)입니다. 숫자 하나인 시간과 분에는 앞에 0이 붙습니다. 예를 들어, 태평양 표준시는 "-08:00"입니다.

:

TimeSeparator에 정의된 기본 시간 구분 문자입니다.

/

DateSeparator에 정의된 기본 날짜 구분 문자입니다.

% c

여기서 c는 단독으로 사용된 경우의 형식 패턴 문자입니다. 즉, "d", "f", "F", "h", "m", "s", "t", "y", "z", "H" 또는 "M" 형식 패턴을 단독으로 사용하려면 "%d", "%f", "%F", "%h", "%m", "%s", "%t", "%y", "%z", "%H" 또는 "%M"을 지정합니다.

형식 패턴 문자가 리터럴 문자나 다른 형식 패턴 문자와 조합되어 사용될 경우 "%" 문자를 생략할 수 있습니다.

\ c

여기서 c는 임의의 문자입니다. 문자를 그대로 표시합니다. 백슬래시 문자를 표시하려면 "\\"을 사용합니다.

위의 두 번째 표에 나열된 형식 패턴을 사용해야만 사용자 지정 패턴을 만들 수 있으며, 첫 번째 표에 나열된 표준 형식 문자를 사용하면 사용자 지정 패턴을 만들 수 없습니다. 사용자 지정 패턴은 다음처럼 최소한 두 문자 길이입니다.

  • DateTime.ToString( "d" )는 DateTime 값을 반환합니다. "d"는 간단한 날짜 패턴의 표준입니다.

  • DateTime.ToString( "%d" )는 월의 일자를 반환합니다. "%d"는 사용자 지정 패턴입니다.

  • DateTime.ToString( "d " )는 월의 일자와 그 다음에 공백 문자를 반환합니다. "d "는 사용자 지정 패턴입니다.

중립 culture가 아닌 불변 culture나 특정 culture에 대해서만 DateTimeFormatInfo 또는 NumberFormatInfo를 만들 수 있습니다. 불변 culture, 특정 culture 및 중립 culture에 대한 자세한 내용은 CultureInfo 클래스를 참조하십시오.

이 클래스는 DateTimeFormatInfo 개체를 복제할 수 있는 ICloneable 인터페이스를 구현합니다. 또한 응용 프로그램에 형식 지정 정보를 제공하는 IFormatProvider를 구현합니다.

예제

다음 코드 예제에서는 형식 문자를 사용하여 en-US culture에 대해 서로 다른 형식 패턴을 출력합니다. 또한 해당 형식 문자와 관련된 속성 값을 표시합니다.

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Public Class SamplesDTFI

   Public Shared Sub Main()

      ' Creates and initializes a DateTimeFormatInfo associated with the en-US culture.
      Dim myDTFI As DateTimeFormatInfo = New CultureInfo("en-US", False).DateTimeFormat
      
      ' Creates a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3).
      ' The Gregorian calendar is the default calendar for the en-US culture.
      Dim myDT As New DateTime(2002, 1, 3)
      
      ' Displays the format pattern associated with each format character.
      Console.WriteLine("FORMAT  en-US EXAMPLE")
      Console.WriteLine("CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY")
      Console.WriteLine()
      Console.WriteLine("  d     {0}", myDT.ToString("d"))
      Console.WriteLine("        {0} {1}", myDTFI.ShortDatePattern, "(ShortDatePattern)")
      Console.WriteLine()
      Console.WriteLine("  D     {0}", myDT.ToString("D"))
      Console.WriteLine("        {0} {1}", myDTFI.LongDatePattern, "(LongDatePattern)")
      Console.WriteLine()
      Console.WriteLine("  f     {0}", myDT.ToString("f"))
      Console.WriteLine()
      Console.WriteLine("  F     {0}", myDT.ToString("F"))
      Console.WriteLine("        {0} {1}", myDTFI.FullDateTimePattern, "(FullDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  g     {0}", myDT.ToString("g"))
      Console.WriteLine()
      Console.WriteLine("  G     {0}", myDT.ToString("G"))
      Console.WriteLine()
      Console.WriteLine("  m     {0}", myDT.ToString("m"))
      Console.WriteLine("        {0} {1}", myDTFI.MonthDayPattern, "(MonthDayPattern)")
      Console.WriteLine()
      Console.WriteLine("  M     {0}", myDT.ToString("M"))
      Console.WriteLine("        {0} {1}", myDTFI.MonthDayPattern, "(MonthDayPattern)")
      Console.WriteLine()
      Console.WriteLine("  r     {0}", myDT.ToString("r"))
      Console.WriteLine("        {0} {1}", myDTFI.RFC1123Pattern, "(RFC1123Pattern)")
      Console.WriteLine()
      Console.WriteLine("  R     {0}", myDT.ToString("R"))
      Console.WriteLine("        {0} {1}", myDTFI.RFC1123Pattern, "(RFC1123Pattern)")
      Console.WriteLine()
      Console.WriteLine("  s     {0}", myDT.ToString("s"))
      Console.WriteLine("        {0} {1}", myDTFI.SortableDateTimePattern, "(SortableDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  t     {0}", myDT.ToString("t"))
      Console.WriteLine("        {0} {1}", myDTFI.ShortTimePattern, "(ShortTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  T     {0}", myDT.ToString("T"))
      Console.WriteLine("        {0} {1}", myDTFI.LongTimePattern, "(LongTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  u     {0}", myDT.ToString("u"))
      Console.WriteLine("        {0} {1}", myDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  U     {0}", myDT.ToString("U"))
      Console.WriteLine()
      Console.WriteLine("  y     {0}", myDT.ToString("y"))
      Console.WriteLine("        {0} {1}", myDTFI.YearMonthPattern, "(YearMonthPattern)")
      Console.WriteLine()
      Console.WriteLine("  Y     {0}", myDT.ToString("Y"))
      Console.WriteLine("        {0} {1}", myDTFI.YearMonthPattern, "(YearMonthPattern)")

   End Sub 'Main 

End Class 'SamplesDTFI


'This code produces the following output.
'
'FORMAT  en-US EXAMPLE
'CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY
'
'  d     1/3/2002
'        M/d/yyyy (ShortDatePattern)
'
'  D     Thursday, January 03, 2002
'        dddd, MMMM dd, yyyy (LongDatePattern)
'
'  f     Thursday, January 03, 2002 12:00 AM
'
'  F     Thursday, January 03, 2002 12:00:00 AM
'        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)
'
'  g     1/3/2002 12:00 AM
'
'  G     1/3/2002 12:00:00 AM
'
'  m     January 03
'        MMMM dd (MonthDayPattern)
'
'  M     January 03
'        MMMM dd (MonthDayPattern)
'
'  r     Thu, 03 Jan 2002 00:00:00 GMT
'        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
'
'  R     Thu, 03 Jan 2002 00:00:00 GMT
'        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
'
'  s     2002-01-03T00:00:00
'        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)
'
'  t     12:00 AM
'        h:mm tt (ShortTimePattern)
'
'  T     12:00:00 AM
'        h:mm:ss tt (LongTimePattern)
'
'  u     2002-01-03 00:00:00Z
'        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)
'
'  U     Thursday, January 03, 2002 8:00:00 AM
'
'  y     January, 2002
'        MMMM, yyyy (YearMonthPattern)
'
'  Y     January, 2002
'        MMMM, yyyy (YearMonthPattern)
'
using System;
using System.Globalization;


public class SamplesDTFI  {

   public static void Main()  {

      // Creates and initializes a DateTimeFormatInfo associated with the en-US culture.
      DateTimeFormatInfo myDTFI = new CultureInfo( "en-US", false ).DateTimeFormat;

      // Creates a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3).
      // The Gregorian calendar is the default calendar for the en-US culture.
      DateTime myDT = new DateTime( 2002, 1, 3 );

      // Displays the format pattern associated with each format character.
      Console.WriteLine( "FORMAT  en-US EXAMPLE" );
      Console.WriteLine( "CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY\n" );
      Console.WriteLine( "  d     {0}", myDT.ToString("d") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.ShortDatePattern, "(ShortDatePattern)" );
      Console.WriteLine( "  D     {0}", myDT.ToString("D") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.LongDatePattern, "(LongDatePattern)" );
      Console.WriteLine( "  f     {0}\n", myDT.ToString("f") );
      Console.WriteLine( "  F     {0}", myDT.ToString("F") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.FullDateTimePattern, "(FullDateTimePattern)" );
      Console.WriteLine( "  g     {0}\n", myDT.ToString("g") );
      Console.WriteLine( "  G     {0}\n", myDT.ToString("G") );
      Console.WriteLine( "  m     {0}", myDT.ToString("m") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.MonthDayPattern, "(MonthDayPattern)" );
      Console.WriteLine( "  M     {0}", myDT.ToString("M") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.MonthDayPattern, "(MonthDayPattern)" );
      Console.WriteLine( "  r     {0}", myDT.ToString("r") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.RFC1123Pattern, "(RFC1123Pattern)" );
      Console.WriteLine( "  R     {0}", myDT.ToString("R") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.RFC1123Pattern, "(RFC1123Pattern)" );
      Console.WriteLine( "  s     {0}", myDT.ToString("s") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.SortableDateTimePattern, "(SortableDateTimePattern)" );
      Console.WriteLine( "  t     {0}", myDT.ToString("t") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.ShortTimePattern, "(ShortTimePattern)" );
      Console.WriteLine( "  T     {0}", myDT.ToString("T") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.LongTimePattern, "(LongTimePattern)" );
      Console.WriteLine( "  u     {0}", myDT.ToString("u") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)" );
      Console.WriteLine( "  U     {0}\n", myDT.ToString("U") );
      Console.WriteLine( "  y     {0}", myDT.ToString("y") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.YearMonthPattern, "(YearMonthPattern)" );
      Console.WriteLine( "  Y     {0}", myDT.ToString("Y") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.YearMonthPattern, "(YearMonthPattern)" );

   }

}

/*
This code produces the following output.

FORMAT  en-US EXAMPLE
CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY

  d     1/3/2002
        M/d/yyyy (ShortDatePattern)

  D     Thursday, January 03, 2002
        dddd, MMMM dd, yyyy (LongDatePattern)

  f     Thursday, January 03, 2002 12:00 AM

  F     Thursday, January 03, 2002 12:00:00 AM
        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

  g     1/3/2002 12:00 AM

  G     1/3/2002 12:00:00 AM

  m     January 03
        MMMM dd (MonthDayPattern)

  M     January 03
        MMMM dd (MonthDayPattern)

  r     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  R     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  s     2002-01-03T00:00:00
        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

  t     12:00 AM
        h:mm tt (ShortTimePattern)

  T     12:00:00 AM
        h:mm:ss tt (LongTimePattern)

  u     2002-01-03 00:00:00Z
        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

  U     Thursday, January 03, 2002 8:00:00 AM

  y     January, 2002
        MMMM, yyyy (YearMonthPattern)

  Y     January, 2002
        MMMM, yyyy (YearMonthPattern)

*/
using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates and initializes a DateTimeFormatInfo associated with the en-US culture.
   CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false );
   DateTimeFormatInfo^ myDTFI = MyCI->DateTimeFormat;
   
   // Creates a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3).
   // The Gregorian calendar is the default calendar for the en-US culture.
   DateTime myDT = DateTime(2002,1,3);
   
   // Displays the format pattern associated with each format character.
   Console::WriteLine( "FORMAT  en-US EXAMPLE" );
   Console::WriteLine( "CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY\n" );
   Console::WriteLine( "  d {0}", myDT.ToString( "d" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->ShortDatePattern, "(ShortDatePattern)" );
   Console::WriteLine( "  D {0}", myDT.ToString( "D" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->LongDatePattern, "(LongDatePattern)" );
   Console::WriteLine( "  f {0}\n", myDT.ToString( "f" ) );
   Console::WriteLine( "  F {0}", myDT.ToString( "F" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->FullDateTimePattern, "(FullDateTimePattern)" );
   Console::WriteLine( "  g {0}\n", myDT.ToString( "g" ) );
   Console::WriteLine( "  G {0}\n", myDT.ToString( "G" ) );
   Console::WriteLine( "  m {0}", myDT.ToString( "m" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->MonthDayPattern, "(MonthDayPattern)" );
   Console::WriteLine( "  M {0}", myDT.ToString( "M" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->MonthDayPattern, "(MonthDayPattern)" );
   Console::WriteLine( "  r {0}", myDT.ToString( "r" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->RFC1123Pattern, "(RFC1123Pattern)" );
   Console::WriteLine( "  R {0}", myDT.ToString( "R" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->RFC1123Pattern, "(RFC1123Pattern)" );
   Console::WriteLine( "  s {0}", myDT.ToString( "s" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->SortableDateTimePattern, "(SortableDateTimePattern)" );
   Console::WriteLine( "  t {0}", myDT.ToString( "t" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->ShortTimePattern, "(ShortTimePattern)" );
   Console::WriteLine( "  T {0}", myDT.ToString( "T" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->LongTimePattern, "(LongTimePattern)" );
   Console::WriteLine( "  u {0}", myDT.ToString( "u" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)" );
   Console::WriteLine( "  U {0}\n", myDT.ToString( "U" ) );
   Console::WriteLine( "  y {0}", myDT.ToString( "y" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->YearMonthPattern, "(YearMonthPattern)" );
   Console::WriteLine( "  Y {0}", myDT.ToString( "Y" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->YearMonthPattern, "(YearMonthPattern)" );
}

/*
This code produces the following output.

FORMAT  en-US EXAMPLE
CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY

d     1/3/2002
M/d/yyyy (ShortDatePattern)

D     Thursday, January 03, 2002
dddd, MMMM dd, yyyy (LongDatePattern)

f     Thursday, January 03, 2002 12:00 AM

F     Thursday, January 03, 2002 12:00:00 AM
dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

g     1/3/2002 12:00 AM

G     1/3/2002 12:00:00 AM

m     January 03
MMMM dd (MonthDayPattern)

M     January 03
MMMM dd (MonthDayPattern)

r     Thu, 03 Jan 2002 00:00:00 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

R     Thu, 03 Jan 2002 00:00:00 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

s     2002-01-03T00:00:00
yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

t     12:00 AM
h:mm tt (ShortTimePattern)

T     12:00:00 AM
h:mm:ss tt (LongTimePattern)

u     2002-01-03 00:00:00Z
yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

U     Thursday, January 03, 2002 8:00:00 AM

y     January, 2002
MMMM, yyyy (YearMonthPattern)

Y     January, 2002
MMMM, yyyy (YearMonthPattern)

*/
import System.* ;
import System.Globalization.* ;

public class SamplesDTFI
{
    public static void main(String[] args)
    {
        // Creates and initializes a DateTimeFormatInfo associated with 
        // the en-US culture.
        DateTimeFormatInfo myDTFI = 
            (new CultureInfo("en-US", false)).get_DateTimeFormat();

        // Creates a DateTime with the Gregorian date January 3, 2002 
        // (year=2002, month=1, day=3).
        // The Gregorian calendar is the default calendar for the 
        // en-US culture.
        DateTime myDT =  new DateTime(2002, 1, 3);

        // Displays the format pattern associated with each format character.
        Console.WriteLine("FORMAT  en-US EXAMPLE");
        Console.WriteLine("CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY\n");
        Console.WriteLine("  d     {0}", myDT.ToString("d"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_ShortDatePattern(),
            "(ShortDatePattern)");
        Console.WriteLine("  D     {0}", myDT.ToString("D"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_LongDatePattern(), 
            "(LongDatePattern)");
        Console.WriteLine("  f     {0}\n", myDT.ToString("f"));
        Console.WriteLine("  F     {0}", myDT.ToString("F"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_FullDateTimePattern(),
            "(FullDateTimePattern)");
        Console.WriteLine("  g     {0}\n", myDT.ToString("g"));
        Console.WriteLine("  G     {0}\n", myDT.ToString("G"));
        Console.WriteLine("  m     {0}", myDT.ToString("m"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_MonthDayPattern(), 
            "(MonthDayPattern)");
        Console.WriteLine("  M     {0}", myDT.ToString("M"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_MonthDayPattern(), 
            "(MonthDayPattern)");
        Console.WriteLine("  r     {0}", myDT.ToString("r"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_RFC1123Pattern(),
            "(RFC1123Pattern)");
        Console.WriteLine("  R     {0}", myDT.ToString("R"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_RFC1123Pattern(), 
            "(RFC1123Pattern)");
        Console.WriteLine("  s     {0}", myDT.ToString("s"));
        Console.WriteLine("        {0} {1}\n", 
            myDTFI.get_SortableDateTimePattern(), "(SortableDateTimePattern)");
        Console.WriteLine("  t     {0}", myDT.ToString("t"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_ShortTimePattern(),
            "(ShortTimePattern)");
        Console.WriteLine("  T     {0}", myDT.ToString("T"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_LongTimePattern(), 
            "(LongTimePattern)");
        Console.WriteLine("  u     {0}", myDT.ToString("u"));
        Console.WriteLine("        {0} {1}\n", 
            myDTFI.get_UniversalSortableDateTimePattern(), 
            "(UniversalSortableDateTimePattern)");
        Console.WriteLine("  U     {0}\n", myDT.ToString("U"));
        Console.WriteLine("  y     {0}", myDT.ToString("y"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_YearMonthPattern(),
            "(YearMonthPattern)");
        Console.WriteLine("  Y     {0}", myDT.ToString("Y"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_YearMonthPattern(),
            "(YearMonthPattern)");
    } //main 
} //SamplesDTFI

/*
This code produces the following output.

FORMAT  en-US EXAMPLE
CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY

  d     1/3/2002
        M/d/yyyy (ShortDatePattern)

  D     Thursday, January 03, 2002
        dddd, MMMM dd, yyyy (LongDatePattern)

  f     Thursday, January 03, 2002 12:00 AM

  F     Thursday, January 03, 2002 12:00:00 AM
        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

  g     1/3/2002 12:00 AM

  G     1/3/2002 12:00:00 AM

  m     January 03
        MMMM dd (MonthDayPattern)

  M     January 03
        MMMM dd (MonthDayPattern)

  r     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  R     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  s     2002-01-03T00:00:00
        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

  t     12:00 AM
        h:mm tt (ShortTimePattern)

  T     12:00:00 AM
        h:mm:ss tt (LongTimePattern)

  u     2002-01-03 00:00:00Z
        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

  U     Thursday, January 03, 2002 8:00:00 AM

  y     January, 2002
        MMMM, yyyy (YearMonthPattern)

  Y     January, 2002
        MMMM, yyyy (YearMonthPattern)
*/

상속 계층 구조

System.Object
  System.Globalization.DateTimeFormatInfo

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

DateTimeFormatInfo 멤버
System.Globalization 네임스페이스
DateTime
Calendar 클래스
CultureInfo 클래스

기타 리소스

형식 지정
형식 지정 개요
표준 DateTime 형식 문자열
사용자 지정 DateTime 형식 문자열