DateTimeOffset.ParseExact 메서드

정의

날짜 및 시간에 대한 지정된 문자열 표현을 해당 DateTimeOffset으로 변환합니다. 문자열 표현의 형식이 지정된 형식과 정확하게 일치해야 합니다.

오버로드

ParseExact(String, String[], IFormatProvider, DateTimeStyles)

지정된 형식, 문화권별 형식 정보 및 스타일을 사용하여 지정된 날짜와 시간의 문자열 표현을 해당 DateTimeOffset 표현으로 변환합니다. 문자열 표시의 형식은 지정된 형식 중 하나와 정확히 일치해야 합니다.

ParseExact(String, String, IFormatProvider, DateTimeStyles)

지정된 형식, 문화권별 형식 정보 및 스타일을 사용하여 날짜 및 시간의 지정된 문자열 표현을 해당 DateTimeOffset으로 변환합니다. 문자열 표현의 형식이 지정된 형식과 정확하게 일치해야 합니다.

ParseExact(String, String, IFormatProvider)

지정된 형식 및 문화권별 형식 정보를 사용하여 날짜 및 시간의 지정된 문자열 표현을 해당 DateTimeOffset으로 변환합니다. 문자열 표현의 형식이 지정된 형식과 정확하게 일치해야 합니다.

ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles)

지정된 형식, 문화권별 형식 정보 및 스타일을 사용하여 날짜 및 시간을 나타내는 문자 범위를 해당 DateTimeOffset으로 변환합니다. 날짜 및 시간 표현의 형식이 지정된 형식과 정확하게 일치해야 합니다.

ParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles)

지정된 형식, 문화권별 형식 정보 및 스타일을 사용하여 지정된 날짜와 시간의 문자열 표현을 해당 DateTimeOffset으로 변환합니다. 날짜 및 시간 표현의 형식은 지정된 형식 중 하나와 정확히 일치해야 합니다.

ParseExact(String, String[], IFormatProvider, DateTimeStyles)

지정된 형식, 문화권별 형식 정보 및 스타일을 사용하여 지정된 날짜와 시간의 문자열 표현을 해당 DateTimeOffset 표현으로 변환합니다. 문자열 표시의 형식은 지정된 형식 중 하나와 정확히 일치해야 합니다.

public:
 static DateTimeOffset ParseExact(System::String ^ input, cli::array <System::String ^> ^ formats, IFormatProvider ^ formatProvider, System::Globalization::DateTimeStyles styles);
public static DateTimeOffset ParseExact (string input, string[] formats, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles);
public static DateTimeOffset ParseExact (string input, string[] formats, IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles);
static member ParseExact : string * string[] * IFormatProvider * System.Globalization.DateTimeStyles -> DateTimeOffset
Public Shared Function ParseExact (input As String, formats As String(), formatProvider As IFormatProvider, styles As DateTimeStyles) As DateTimeOffset

매개 변수

input
String

변환할 날짜 및 시간이 포함된 문자열입니다.

formats
String[]

input의 예상 형식을 정의하는 형식 지정자의 배열입니다.

formatProvider
IFormatProvider

input에 대한 문화권별 형식 지정 정보를 제공하는 개체입니다.

styles
DateTimeStyles

input에 사용할 수 있는 형식을 나타내는 열거형 값의 비트 조합입니다.

반환

DateTimeOffset

formats, formatProviderstyles 매개 변수에 의해 지정된 대로 input 매개 변수에 포함된 날짜 및 시간과 같은 개체입니다.

예외

오프셋이 14시간보다 크거나 -14시간보다 작습니다.

또는

styles에 지원되지 않는 값이 포함되어 있습니다.

또는

styles 매개 변수에 함께 사용할 수 없는 DateTimeStyles 값이 들어 있습니다.

input이(가) null인 경우

input가 빈 문자열("")인 경우

또는

input에 날짜 및 시간의 유효한 문자열 표현이 없습니다.

또는

올바른 형식 지정자를 포함하는 formats의 요소가 없습니다.

또는

input의 시간 구성 요소와 AM/PM 지정자가 일치하지 않습니다.

예제

다음 예제에서는 날짜 및 시간 및 오프셋 값의 문자열 표현에 대해 여러 입력 형식을 정의한 다음 사용자가 입력한 문자열을 메서드에 DateTimeOffset.ParseExact(String, String[], IFormatProvider, DateTimeStyles) 전달합니다.

TextReader conIn = Console.In;
TextWriter conOut = Console.Out;
int tries = 0;
string input = String.Empty;
string[] formats = new string[] {@"@M/dd/yyyy HH:m zzz", @"MM/dd/yyyy HH:m zzz",
                                 @"M/d/yyyy HH:m zzz", @"MM/d/yyyy HH:m zzz",
                                 @"M/dd/yy HH:m zzz", @"MM/dd/yy HH:m zzz",
                                 @"M/d/yy HH:m zzz", @"MM/d/yy HH:m zzz",
                                 @"M/dd/yyyy H:m zzz", @"MM/dd/yyyy H:m zzz",
                                 @"M/d/yyyy H:m zzz", @"MM/d/yyyy H:m zzz",
                                 @"M/dd/yy H:m zzz", @"MM/dd/yy H:m zzz",
                                 @"M/d/yy H:m zzz", @"MM/d/yy H:m zzz",
                                 @"M/dd/yyyy HH:mm zzz", @"MM/dd/yyyy HH:mm zzz",
                                 @"M/d/yyyy HH:mm zzz", @"MM/d/yyyy HH:mm zzz",
                                 @"M/dd/yy HH:mm zzz", @"MM/dd/yy HH:mm zzz",
                                 @"M/d/yy HH:mm zzz", @"MM/d/yy HH:mm zzz",
                                 @"M/dd/yyyy H:mm zzz", @"MM/dd/yyyy H:mm zzz",
                                 @"M/d/yyyy H:mm zzz", @"MM/d/yyyy H:mm zzz",
                                 @"M/dd/yy H:mm zzz", @"MM/dd/yy H:mm zzz",
                                 @"M/d/yy H:mm zzz", @"MM/d/yy H:mm zzz"};
IFormatProvider provider = CultureInfo.InvariantCulture.DateTimeFormat;
DateTimeOffset result = new DateTimeOffset();

do {
   conOut.WriteLine("Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),");
   conOut.Write("Then press Enter: ");
   input = conIn.ReadLine();
   conOut.WriteLine();
   try
   {
      result = DateTimeOffset.ParseExact(input, formats, provider,
                                         DateTimeStyles.AllowWhiteSpaces);
      break;
   }
   catch (FormatException)
   {
      Console.WriteLine("Unable to parse {0}.", input);
      tries++;
   }
} while (tries < 3);
if (tries >= 3)
   Console.WriteLine("Exiting application without parsing {0}", input);
else
   Console.WriteLine("{0} was converted to {1}", input, result.ToString());
// Some successful sample interactions with the user might appear as follows:
//    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
//    Then press Enter: 12/08/2007 6:54 -6:00
//
//    12/08/2007 6:54 -6:00 was converted to 12/8/2007 6:54:00 AM -06:00
//
//    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
//    Then press Enter: 12/8/2007 06:54 -06:00
//
//    12/8/2007 06:54 -06:00 was converted to 12/8/2007 6:54:00 AM -06:00
//
//    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
//    Then press Enter: 12/5/07 6:54 -6:00
//
//    12/5/07 6:54 -6:00 was converted to 12/5/2007 6:54:00 AM -06:00
let input = String.Empty
let formats = 
    [| @"@M/dd/yyyy HH:m zzz"; @"MM/dd/yyyy HH:m zzz";
       @"M/d/yyyy HH:m zzz"; @"MM/d/yyyy HH:m zzz"
       @"M/dd/yy HH:m zzz"; @"MM/dd/yy HH:m zzz"
       @"M/d/yy HH:m zzz"; @"MM/d/yy HH:m zzz"
       @"M/dd/yyyy H:m zzz"; @"MM/dd/yyyy H:m zzz"
       @"M/d/yyyy H:m zzz"; @"MM/d/yyyy H:m zzz"
       @"M/dd/yy H:m zzz"; @"MM/dd/yy H:m zzz"
       @"M/d/yy H:m zzz"; @"MM/d/yy H:m zzz"
       @"M/dd/yyyy HH:mm zzz"; @"MM/dd/yyyy HH:mm zzz"
       @"M/d/yyyy HH:mm zzz"; @"MM/d/yyyy HH:mm zzz"
       @"M/dd/yy HH:mm zzz"; @"MM/dd/yy HH:mm zzz"
       @"M/d/yy HH:mm zzz"; @"MM/d/yy HH:mm zzz"
       @"M/dd/yyyy H:mm zzz"; @"MM/dd/yyyy H:mm zzz"
       @"M/d/yyyy H:mm zzz"; @"MM/d/yyyy H:mm zzz"
       @"M/dd/yy H:mm zzz"; @"MM/dd/yy H:mm zzz"
       @"M/d/yy H:mm zzz"; @"MM/d/yy H:mm zzz" |]
let provider = CultureInfo.InvariantCulture.DateTimeFormat

let mutable result = None
let mutable tries = 0
while tries < 3 && result.IsNone do
    printfn "Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),"
    printf "Then press Enter: "
    let input = stdin.ReadLine()
    printfn ""
    try
        result <- 
            DateTimeOffset.ParseExact(input, formats, provider, DateTimeStyles.AllowWhiteSpaces) 
            |> Some
    with :? FormatException ->
        printfn $"Unable to parse {input}."
        tries <- tries + 1

match result with
| Some result ->
    printfn $"{input} was converted to {result}"
| None ->
    printfn $"Exiting application without parsing {input}"

// Some successful sample interactions with the user might appear as follows:
//    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
//    Then press Enter: 12/08/2007 6:54 -6:00
//
//    12/08/2007 6:54 -6:00 was converted to 12/8/2007 6:54:00 AM -06:00
//
//    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
//    Then press Enter: 12/8/2007 06:54 -06:00
//
//    12/8/2007 06:54 -06:00 was converted to 12/8/2007 6:54:00 AM -06:00
//
//    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
//    Then press Enter: 12/5/07 6:54 -6:00
//
//    12/5/07 6:54 -6:00 was converted to 12/5/2007 6:54:00 AM -06:00
 Dim conIn As TextReader = Console.In
 Dim conOut As TextWriter = Console.Out
 Dim tries As Integer = 0
 Dim input As String = String.Empty
 Dim formats() As String = {"M/dd/yyyy HH:m zzz", "MM/dd/yyyy HH:m zzz", _
                            "M/d/yyyy HH:m zzz", "MM/d/yyyy HH:m zzz", _
                            "M/dd/yy HH:m zzz", "MM/dd/yy HH:m zzz", _
                            "M/d/yy HH:m zzz", "MM/d/yy HH:m zzz", _                                 
                            "M/dd/yyyy H:m zzz", "MM/dd/yyyy H:m zzz", _
                            "M/d/yyyy H:m zzz", "MM/d/yyyy H:m zzz", _
                            "M/dd/yy H:m zzz", "MM/dd/yy H:m zzz", _
                            "M/d/yy H:m zzz", "MM/d/yy H:m zzz", _                               
                            "M/dd/yyyy HH:mm zzz", "MM/dd/yyyy HH:mm zzz", _
                            "M/d/yyyy HH:mm zzz", "MM/d/yyyy HH:mm zzz", _
                            "M/dd/yy HH:mm zzz", "MM/dd/yy HH:mm zzz", _
                            "M/d/yy HH:mm zzz", "MM/d/yy HH:mm zzz", _                                 
                            "M/dd/yyyy H:mm zzz", "MM/dd/yyyy H:mm zzz", _
                            "M/d/yyyy H:mm zzz", "MM/d/yyyy H:mm zzz", _
                            "M/dd/yy H:mm zzz", "MM/dd/yy H:mm zzz", _
                            "M/d/yy H:mm zzz", "MM/d/yy H:mm zzz"}   
 Dim provider As IFormatProvider = CultureInfo.InvariantCulture.DateTimeFormat
 Dim result As DateTimeOffset

 Do 
    conOut.WriteLine("Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),")
    conOut.Write("Then press Enter: ")
    input = conIn.ReadLine()
    conOut.WriteLine() 
    Try
       result = DateTimeOffset.ParseExact(input, formats, provider, _
                                          DateTimeStyles.AllowWhiteSpaces)
       Exit Do
    Catch e As FormatException
       Console.WriteLine("Unable to parse {0}.", input)      
       tries += 1
    End Try
 Loop While tries < 3
 If tries >= 3 Then
    Console.WriteLine("Exiting application without parsing {0}", input)
 Else
    Console.WriteLine("{0} was converted to {1}", input, result.ToString())                                                     
 End If 
 ' Some successful sample interactions with the user might appear as follows:
 '    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
 '    Then press Enter: 12/08/2007 6:54 -6:00
 '    
 '    12/08/2007 6:54 -6:00 was converted to 12/8/2007 6:54:00 AM -06:00         
 '    
 '    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
 '    Then press Enter: 12/8/2007 06:54 -06:00
 '    
 '    12/8/2007 06:54 -06:00 was converted to 12/8/2007 6:54:00 AM -06:00
 '    
 '    Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM),
 '    Then press Enter: 12/5/07 6:54 -6:00
 '    
 '    12/5/07 6:54 -6:00 was converted to 12/5/2007 6:54:00 AM -06:00

설명

이 메서드는 DateTimeOffset.ParseExact(String, String[], IFormatProvider, DateTimeStyles) 매개 변수에 할당된 패턴 중 하나와 일치하는 날짜의 문자열 표현을 formats 구문 분석합니다. 문자열이 input 이러한 패턴 중 하나와 매개 변수로 styles 정의된 변형 중 하나와 일치하지 않는 경우 메서드는 을 throw합니다 FormatException. 여러 서식 지정 패턴과 비교하는 input 것 외에도 이 오버로드는 메서드와 동일하게 DateTimeOffset.ParseExact(String, String, IFormatProvider, DateTimeStyles) 동작합니다.

매개 변수는 formats 해당 요소에 단일 표준 형식 지정자 또는 매개 변수의 input 가능한 패턴을 정의하는 하나 이상의 사용자 지정 형식 지정자를 포함하는 문자열 배열입니다. 메서드가 호출 input 되면 이러한 패턴 중 하나와 일치해야 합니다. 유효한 서식 코드에 대한 자세한 내용은 표준 날짜 및 시간 형식 문자열 및 사용자 지정 날짜 및 시간 형식 문자열을 참조하세요. 일치하는 요소에 formats 오프셋이 있어야 input함을 나타내는 사용자 지정 형식 지정자가 포함된 z``zz``zzz 경우 해당 오프셋에는 음수 기호 또는 양수 기호가 포함되어야 합니다. 기호가 없으면 메서드는 .를 FormatExceptionthrow합니다.

중요

formats 이 오버로드의 매개 변수를 사용하여 여러 형식을 지정하면 많은 사용자가 날짜와 시간을 입력할 때 발생하는 불만을 줄일 수 있습니다. 특히 여러 개의 입력된 패턴을 정의 하는 기능 포함 하거나 부족 한 월, 일, 시간, 분 및 초를 앞에 오는 0 수 있는 날짜와 시간 표현을 처리 하도록 애플리케이션을 수 있습니다. 이 예제에서는 이에 대한 그림을 제공합니다.

일치하는 요소에 formats 날짜가 input 포함되어야 하지만 시간이 없는 경우 결과 DateTimeOffset 개체에 자정(0:00:00)의 시간이 할당됩니다. 일치하는 요소에 formats 날짜가 아닌 시간을 포함해야 하는 input 경우 결과 DateTimeOffset 개체에 로컬 시스템의 현재 날짜가 할당됩니다. 일치하는 요소가 formats 오프셋을 input 포함할 필요가 없는 경우 결과 DateTimeOffset 개체의 오프셋은 매개 변수의 styles 값에 따라 달라집니다. 포함된 AssumeLocal경우 styles 로컬 표준 시간대의 오프셋이 개체에 DateTimeOffset 할당됩니다. 포함AssumeUniversal되는 경우 styles UTC(협정 세계시) 오프셋 또는 +00:00이 개체에 DateTimeOffset 할당됩니다. 두 값을 모두 지정하지 않으면 현지 표준 시간대의 오프셋이 사용됩니다.

사용된 input 특정 날짜 및 시간 기호 및 문자열은 매개 변수에 formatProvider 의해 정의됩니다. 일치하는 요소가 표준 형식 지정자 문자열인 경우 정확한 형식 inputformats 마찬가지입니다. 매개 변수는 formatProvider 다음 중 하나일 수 있습니다.

nullCultureInfo 경우 formatprovider 현재 문화권에 해당하는 개체가 사용됩니다.

매개 변수는 styles 입력 문자열에 공백이 허용되는지 여부를 정의하고 명시적 오프셋 구성 요소가 없는 문자열을 구문 분석하는 방법을 나타내며 구문 분석 작업의 일부로 UTC 변환을 지원합니다. 를 제외한 NoCurrentDateDefault열거형의 DateTimeStyles 모든 멤버가 지원됩니다. 다음 표에서는 지원되는 각 멤버의 효과를 나열합니다.

DateTimeStyles 멤버 동작
AdjustToUniversal input 구문 분석하고 필요한 경우 UTC로 변환합니다. 문자열을 구문 분석한 다음 반환 DateTimeOffset 된 개체의 메서드를 DateTimeOffset.ToUniversalTime 호출하는 것과 같습니다.
AssumeLocal 일치하는 요소가 formats 오프셋 값을 포함할 필요가 input 없으면 반환 DateTimeOffset 된 개체에 현지 표준 시간대의 오프셋이 제공됩니다. 기본값입니다.
AssumeUniversal 일치하는 요소에 formats 오프셋 값이 input 필요하지 않은 경우 반환 DateTimeOffset 된 개체에 UTC 오프셋(+00:00)이 지정됩니다.
AllowInnerWhite input 의해 format지정되지 않은 내부 공백을 포함할 수 있습니다. 추가 공백은 날짜 및 시간 구성 요소와 개별 구성 요소(오프셋 제외) 내에 표시될 수 있으며 문자열을 구문 분석할 때 무시됩니다.
AllowLeadingWhite input 지정되지 않은 선행 공백을 formats포함할 수 있습니다. 문자열을 구문 분석할 때 무시됩니다.
AllowTrailingWhite 에서 input 지정하지 않은 후행 공백을 formats포함할 수 있습니다. 문자열을 구문 분석할 때 무시됩니다.
AllowWhiteSpaces input 지정되지 않은 선행, 후행 및 내부 공백을 formats포함할 수 있습니다. 문자열을 구문 분석할 때 일치하는 요소 formats 에 지정되지 않은 추가 공백 문자는 모두 무시됩니다.
None 에서 추가 공백이 허용되지 않음을 input나타냅니다. 일치를 수행하려면 공백이 특정 요소 formats 에 지정된 대로 정확하게 표시되어야 합니다. 기본 동작입니다.
RoundtripKind 구조체에 속성이 DateTimeOffset 없기 Kind 때문에 아무런 효과가 없습니다.

호출자 참고

.NET Framework 4 ParseExact 에서 메서드는 구문 분석할 문자열에 시간 구성 요소와 합의되지 않은 AM/PM 지정자가 포함된 경우를 throw FormatException 합니다. .NET Framework 3.5 이전 버전에서는 AM/PM 지정자가 무시됩니다.

추가 정보

적용 대상

ParseExact(String, String, IFormatProvider, DateTimeStyles)

지정된 형식, 문화권별 형식 정보 및 스타일을 사용하여 날짜 및 시간의 지정된 문자열 표현을 해당 DateTimeOffset으로 변환합니다. 문자열 표현의 형식이 지정된 형식과 정확하게 일치해야 합니다.

public:
 static DateTimeOffset ParseExact(System::String ^ input, System::String ^ format, IFormatProvider ^ formatProvider, System::Globalization::DateTimeStyles styles);
public static DateTimeOffset ParseExact (string input, string format, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles);
public static DateTimeOffset ParseExact (string input, string format, IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles);
static member ParseExact : string * string * IFormatProvider * System.Globalization.DateTimeStyles -> DateTimeOffset
Public Shared Function ParseExact (input As String, format As String, formatProvider As IFormatProvider, styles As DateTimeStyles) As DateTimeOffset

매개 변수

input
String

변환할 날짜 및 시간이 포함된 문자열입니다.

format
String

input의 예상 형식을 정의하는 형식 지정자입니다.

formatProvider
IFormatProvider

input에 대한 문화권별 형식 지정 정보를 제공하는 개체입니다.

styles
DateTimeStyles

input에 사용할 수 있는 형식을 나타내는 열거형 값의 비트 조합입니다.

반환

DateTimeOffset

format, formatProviderstyles 매개 변수에 의해 지정된 대로 input 매개 변수에 포함된 날짜 및 시간과 같은 개체입니다.

예외

오프셋이 14시간보다 크거나 -14시간보다 작습니다.

또는

styles 매개 변수에 지원되지 않는 값이 포함되어 있습니다.

또는

styles 매개 변수에 함께 사용할 수 없는 DateTimeStyles 값이 들어 있습니다.

input이(가) null인 경우

또는

format이(가) null인 경우

input가 빈 문자열("")인 경우

또는

input에 날짜 및 시간의 유효한 문자열 표현이 없습니다.

또는

format이 빈 문자열인 경우

또는

input의 시간 구성 요소와 AM/PM 지정자가 일치하지 않습니다.

예제

다음 예제에서는 표준 및 사용자 지정 형식 지정자, 고정 문화권 및 다양한 DateTimeStyles 값을 사용하여 DateTimeOffset.ParseExact(String, String, IFormatProvider, DateTimeStyles) 여러 날짜 및 시간 문자열을 구문 분석합니다.

string dateString, format;
DateTimeOffset result;
CultureInfo provider = CultureInfo.InvariantCulture;

// Parse date-only value with invariant culture and assume time is UTC.
dateString = "06/15/2008";
format = "d";
try
{
   result = DateTimeOffset.ParseExact(dateString, format, provider,
                                      DateTimeStyles.AssumeUniversal);
   Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
   Console.WriteLine("'{0}' is not in the correct format.", dateString);
}

// Parse date-only value with leading white space.
// Should throw a FormatException because only trailing white space is
// specified in method call.
dateString = " 06/15/2008";
try
{
   result = DateTimeOffset.ParseExact(dateString, format, provider,
                                      DateTimeStyles.AllowTrailingWhite);
   Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
   Console.WriteLine("'{0}' is not in the correct format.", dateString);
}

// Parse date and time value, and allow all white space.
dateString = " 06/15/   2008  15:15    -05:00";
format = "MM/dd/yyyy H:mm zzz";
try
{
   result = DateTimeOffset.ParseExact(dateString, format, provider,
                                      DateTimeStyles.AllowWhiteSpaces);
   Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
   Console.WriteLine("'{0}' is not in the correct format.", dateString);
}

// Parse date and time and convert to UTC.
dateString = "  06/15/2008 15:15:30 -05:00";
format = "MM/dd/yyyy H:mm:ss zzz";
try
{
   result = DateTimeOffset.ParseExact(dateString, format, provider,
                                      DateTimeStyles.AllowWhiteSpaces |
                                      DateTimeStyles.AdjustToUniversal);
   Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
   Console.WriteLine("'{0}' is not in the correct format.", dateString);
}
// The example displays the following output:
//    '06/15/2008' converts to 6/15/2008 12:00:00 AM +00:00.
//    ' 06/15/2008' is not in the correct format.
//    ' 06/15/   2008  15:15    -05:00' converts to 6/15/2008 3:15:00 PM -05:00.
//    '  06/15/2008 15:15:30 -05:00' converts to 6/15/2008 8:15:30 PM +00:00.
let provider = CultureInfo.InvariantCulture

// Parse date-only value with invariant culture and assume time is UTC.
let dateString = "06/15/2008"
let format = "d"
try
    let result = DateTimeOffset.ParseExact(dateString, format, provider, DateTimeStyles.AssumeUniversal)
    printfn $"'{dateString}' converts to {result}."
with :? FormatException ->
    printfn $"'{dateString}' is not in the correct format."

// Parse date-only value with leading white space.
// Should throw a FormatException because only trailing white space is
// specified in method call.
let dateString = " 06/15/2008"
try
    let result = DateTimeOffset.ParseExact(dateString, format, provider, DateTimeStyles.AllowTrailingWhite)
    printfn $"'{dateString}' converts to {result}."
with :? FormatException ->
    printfn $"'{dateString}' is not in the correct format."

// Parse date and time value, and allow all white space.
let dateString = " 06/15/   2008  15:15    -05:00"
let format = "MM/dd/yyyy H:mm zzz"
try
    let result = DateTimeOffset.ParseExact(dateString, format, provider, DateTimeStyles.AllowWhiteSpaces)
    printfn $"'{dateString}' converts to {result}."
with :? FormatException ->
    printfn $"'{dateString}' is not in the correct format."

// Parse date and time and convert to UTC.
let dateString = "  06/15/2008 15:15:30 -05:00"
let format = "MM/dd/yyyy H:mm:ss zzz"
try
    let result = 
        DateTimeOffset.ParseExact(dateString, format, provider,
                                  DateTimeStyles.AllowWhiteSpaces |||
                                  DateTimeStyles.AdjustToUniversal)
    printfn $"'{dateString}' converts to {result}."
with :? FormatException ->
    printfn $"'{dateString}' is not in the correct format."

// The example displays the following output:
//    '06/15/2008' converts to 6/15/2008 12:00:00 AM +00:00.
//    ' 06/15/2008' is not in the correct format.
//    ' 06/15/   2008  15:15    -05:00' converts to 6/15/2008 3:15:00 PM -05:00.
//    '  06/15/2008 15:15:30 -05:00' converts to 6/15/2008 8:15:30 PM +00:00.
Dim dateString, format As String  
Dim result As DateTimeOffset
Dim provider As CultureInfo = CultureInfo.InvariantCulture

' Parse date-only value with invariant culture and assume time is UTC.
dateString = "06/15/2008"
format = "d"
Try
   result = DateTimeOffset.ParseExact(dateString, format, provider, _
                                      DateTimeStyles.AssumeUniversal)
   Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString())
Catch e As FormatException
   Console.WriteLine("'{0}' is not in the correct format.", dateString)
End Try 

' Parse date-only value with leading white space.
' Should throw a FormatException because only trailing white space is  
' specified in method call.
dateString = " 06/15/2008"
Try
   result = DateTimeOffset.ParseExact(dateString, format, provider, _
                                      DateTimeStyles.AllowTrailingWhite)
   Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString())
Catch e As FormatException
   Console.WriteLine("'{0}' is not in the correct format.", dateString)
End Try 

' Parse date and time value, and allow all white space.
dateString = " 06/15/   2008  15:15    -05:00"
format = "MM/dd/yyyy H:mm zzz"
Try
   result = DateTimeOffset.ParseExact(dateString, format, provider, _
                                      DateTimeStyles.AllowWhiteSpaces)
   Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString())
Catch e As FormatException
   Console.WriteLine("'{0}' is not in the correct format.", dateString)
End Try 

' Parse date and time and convert to UTC.
dateString = "  06/15/2008 15:15:30 -05:00"   
format = "MM/dd/yyyy H:mm:ss zzz"       
Try
   result = DateTimeOffset.ParseExact(dateString, format, provider, _
                                      DateTimeStyles.AllowWhiteSpaces Or _
                                      DateTimeStyles.AdjustToUniversal)
   Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString())
Catch e As FormatException
   Console.WriteLine("'{0}' is not in the correct format.", dateString)
End Try 
' The example displays the following output:
'    '06/15/2008' converts to 6/15/2008 12:00:00 AM +00:00.
'    ' 06/15/2008' is not in the correct format.
'    ' 06/15/   2008  15:15    -05:00' converts to 6/15/2008 3:15:00 PM -05:00.
'    '  06/15/2008 15:15:30 -05:00' converts to 6/15/2008 8:15:30 PM +00:00.

다음 예제에서는 다양한 DateTimeStyles 값을 사용하여 ISO 8601을 준수해야 하는 문자열 배열을 구문 분석합니다. 예제의 출력에서와 같이 적절한 형식의 문자열은 다음과 같은 경우 구문 분석하지 못합니다.

UTC 오프셋을 지정하지 않는 문자열은 메서드 호출에 플래그가 제공되지 않는 한 DateTimeStyles.AssumeUniversal 로컬 표준 시간대의 오프셋(이 경우 -07:00)을 갖는 것으로 간주됩니다. 이 경우 유니버설 조정 시간으로 간주됩니다.

module parseexact_iso8601_2

open System
open System.Globalization

let dateStrings = 
    [| "2018-08-18T12:45:16.0000000Z"
       "2018/08/18T12:45:16.0000000Z"
       "2018-18-08T12:45:16.0000000Z"
       "2018-08-18T12:45:16.0000000"                               
       " 2018-08-18T12:45:16.0000000Z "
       "2018-08-18T12:45:16.0000000+02:00"
       "2018-08-18T12:45:16.0000000-07:00" |] 

let parseWithISO8601 dateStrings styles =
    printfn $"Parsing with {styles}:"
    for dateString in dateStrings do
        try
            let date = DateTimeOffset.ParseExact(dateString, "O", null, styles)
            printfn $"""   {dateString,-35} --> {date.ToString "yyyy-MM-dd HH:mm:ss.FF zzz"}"""
        with :? FormatException ->
            printfn $"   FormatException: Unable to convert '{dateString}'"

parseWithISO8601 dateStrings DateTimeStyles.None
printfn "\n-----\n"
parseWithISO8601 dateStrings DateTimeStyles.AllowWhiteSpaces
printfn "\n-----\n"
parseWithISO8601 dateStrings DateTimeStyles.AdjustToUniversal
printfn "\n-----\n"
parseWithISO8601 dateStrings DateTimeStyles.AssumeLocal
printfn "\n-----\n"
parseWithISO8601 dateStrings DateTimeStyles.AssumeUniversal


// The example displays the following output:
//      Parsing with None:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 12:45:16 -07:00
//         FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
//
//      -----
//
//      Parsing with AllowWhiteSpaces:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 12:45:16 -07:00
//         2018-08-18T12:45:16.0000000Z       --> 2018-08-18 12:45:16 +00:00
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
//
//      -----
//
//      Parsing with AdjustToUniversal:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 19:45:16 +00:00
//         FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 10:45:16 +00:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 19:45:16 +00:00
//
//      -----
//
//      Parsing with AssumeLocal:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 12:45:16 -07:00
//         FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
//
//      -----
//
//      Parsing with AssumeUniversal:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] dateStrings = { "2018-08-18T12:45:16.0000000Z",
                               "2018/08/18T12:45:16.0000000Z",
                               "2018-18-08T12:45:16.0000000Z",
                               "2018-08-18T12:45:16.0000000",                               
                               " 2018-08-18T12:45:16.0000000Z ",
                               "2018-08-18T12:45:16.0000000+02:00",
                               "2018-08-18T12:45:16.0000000-07:00" }; 
      
      ParseWithISO8601(dateStrings, DateTimeStyles.None);
      Console.WriteLine("\n-----\n");
      ParseWithISO8601(dateStrings, DateTimeStyles.AllowWhiteSpaces);
      Console.WriteLine("\n-----\n");
      ParseWithISO8601(dateStrings, DateTimeStyles.AdjustToUniversal);
      Console.WriteLine("\n-----\n");
      ParseWithISO8601(dateStrings, DateTimeStyles.AssumeLocal);
      Console.WriteLine("\n-----\n");
      ParseWithISO8601(dateStrings, DateTimeStyles.AssumeUniversal);   }

   private static void ParseWithISO8601(string[] dateStrings, DateTimeStyles styles)
   {   
      Console.WriteLine($"Parsing with {styles}:");
      foreach (var dateString in dateStrings)
      {
         try {
            var date = DateTimeOffset.ParseExact(dateString, "O", null, styles);
            Console.WriteLine($"   {dateString,-35} --> {date:yyyy-MM-dd HH:mm:ss.FF zzz}");
         }
         catch (FormatException)
         {
            Console.WriteLine($"   FormatException: Unable to convert '{dateString}'");
         }   
      } 
   }
}
// The example displays the following output:
//      Parsing with None:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 12:45:16 -07:00
//         FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
//
//      -----
//
//      Parsing with AllowWhiteSpaces:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 12:45:16 -07:00
//         2018-08-18T12:45:16.0000000Z       --> 2018-08-18 12:45:16 +00:00
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
//
//      -----
//
//      Parsing with AdjustToUniversal:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 19:45:16 +00:00
//         FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 10:45:16 +00:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 19:45:16 +00:00
//
//      -----
//
//      Parsing with AssumeLocal:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 12:45:16 -07:00
//         FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
//
//      -----
//
//      Parsing with AssumeUniversal:
//         2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//         FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//         2018-08-18T12:45:16.0000000         --> 2018-08-18 12:45:16 +00:00
//         FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//         2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//         2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
Imports System.Globalization

Public Module Example
   Public Sub Main()
      Dim dateStrings() = { "2018-08-18T12:45:16.0000000Z",
                            "2018/08/18T12:45:16.0000000Z",
                            "2018-18-08T12:45:16.0000000Z",
                            "2018-08-18T12:45:16.0000000",                               
                            " 2018-08-18T12:45:16.0000000Z ",
                            "2018-08-18T12:45:16.0000000+02:00",
                            "2018-08-18T12:45:16.0000000-07:00" } 
      
      ParseWithISO8601(dateStrings, DateTimeStyles.None)
      Console.WriteLine($"{vbCrLf}-----{vbCrLf}")
      ParseWithISO8601(dateStrings, DateTimeStyles.AllowWhiteSpaces)
      Console.WriteLine($"{vbCrLf}-----{vbCrLf}")
      ParseWithISO8601(dateStrings, DateTimeStyles.AdjustToUniversal)
      Console.WriteLine($"{vbCrLf}-----{vbCrLf}")
      ParseWithISO8601(dateStrings, DateTimeStyles.AssumeLocal)
      Console.WriteLine($"{vbCrLf}-----{vbCrLf}")
      ParseWithISO8601(dateStrings, DateTimeStyles.AssumeUniversal)   
   End Sub

   Private Sub ParseWithISO8601(dateStrings() As String, styles As DateTimeStyles)
      Console.WriteLine($"Parsing with {styles}:")
      For Each dateStr In dateStrings
         Try 
            Dim dat = DateTimeOffset.ParseExact(dateString, "O", Nothing, styles)
            Console.WriteLine($"   {dateString,-35} --> {dat:yyyy-MM-dd HH:mm:ss.FF zzz}")
         catch e As FormatException
            Console.WriteLine($"   FormatException: Unable to convert '{dateString}'")
         End Try   
      Next 
   End Sub
End Module
' The example displays the following output:
'      Parsing with None:
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'
'      -----
'
'      Parsing with AllowWhiteSpaces:
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'
'      -----
'
'      Parsing with AdjustToUniversal:
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'
'      -----
'
'      Parsing with AssumeLocal:
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'
'      -----
'
'      Parsing with AssumeUniversal:
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'
'         FormatException: Unable to convert '07-30-2018'

설명

메서드는 DateTimeOffset.ParseExact(String, String, IFormatProvider, DateTimeStyles) 매개 변수에서 정의한 형식이어야 하는 날짜의 문자열 표현을 format 구문 분석합니다. 또한 날짜 및 시간의 문자열 표현에 대한 , 및 요소가 지정된 format순서대로 표시되어야 합니다<Date>.<Offset> <Time> 문자열이 input 매개 변수의 format 패턴과 일치하지 않는 경우 매개 변수로 styles 정의된 변형이 있는 경우 메서드는 을 throw합니다 FormatException. 반면, 메서드는 DateTimeOffset.Parse(String, IFormatProvider, DateTimeStyles) 형식 공급자의 개체에서 인식되는 형식 중 하나로 날짜의 DateTimeFormatInfo 문자열 표현을 구문 분석합니다. Parse에서는 <Date><Time>날짜 및 시간의 문자열 표현 및 <Offset> 요소를 순서에 따라 표시할 수도 있습니다.

format 매개 변수는 매개 변수의 필수 패턴을 input 정의하는 단일 표준 형식 지정자 또는 하나 이상의 사용자 지정 형식 지정자를 포함하는 문자열입니다. 유효한 서식 코드에 대한 자세한 내용은 표준 날짜 및 시간 형식 문자열 및 사용자 지정 날짜 및 시간 형식 문자열을 참조하세요. 오프셋이 z``zz``zzz 있어야 input함을 나타내는 사용자 지정 형식 지정자를 포함하는 경우 format 해당 오프셋에는 음수 기호 또는 양수 기호가 포함되어야 합니다. 기호가 없으면 메서드가 을 throw합니다 FormatException.

시간이 아닌 날짜를 포함해야 하는 input 경우 format 결과 DateTimeOffset 개체에 자정(0:00:00)의 시간이 할당됩니다. 날짜가 아닌 시간을 포함해야 하는 input 경우 format 결과 DateTimeOffset 개체에 로컬 시스템의 현재 날짜가 할당됩니다. 오프셋을 input 포함하지 않아도 되는 경우 format 결과 DateTimeOffset 개체의 오프셋은 매개 변수 값 styles 에 따라 달라집니다. 포함된 AssumeLocal경우 styles 로컬 표준 시간대의 오프셋이 개체에 DateTimeOffset 할당됩니다. 포함된 AssumeUniversal경우 styles UTC(협정 세계시) 오프셋 또는 +00:00이 개체에 DateTimeOffset 할당됩니다. 두 값을 모두 지정하지 않으면 현지 표준 시간대의 오프셋이 사용됩니다.

사용된 input 특정 날짜 및 시간 기호 및 문자열은 매개 변수에 formatProvider 의해 정의됩니다. 표준 형식 지정자 문자열인 경우 format 정확한 형식의 input경우에도 마찬가지입니다. 매개 변수는 formatProvider 다음 중 하나일 수 있습니다.

nullCultureInfo 경우 formatprovider 현재 문화권에 해당하는 개체가 사용됩니다.

매개 변수는 styles 입력 문자열에서 공백이 허용되는지 여부를 정의하고 명시적 오프셋 구성 요소가 없는 문자열을 구문 분석하는 방법을 나타내며 구문 분석 작업의 일부로 UTC 변환을 지원합니다. 를 제외한 NoCurrentDateDefault열거형의 DateTimeStyles 모든 멤버가 지원됩니다. 다음 표에서는 지원되는 각 멤버의 효과를 나열합니다.

DateTimeStyles 멤버 동작
AdjustToUniversal input 구문 분석하고 필요한 경우 UTC로 변환합니다. 문자열을 구문 분석한 다음 반환 DateTimeOffset 된 개체의 메서드를 호출하는 DateTimeOffset.ToUniversalTime 것과 같습니다.
AssumeLocal 오프셋 값이 input 필요하지 않은 경우 format 반환 DateTimeOffset 된 개체에 현지 표준 시간대의 오프셋이 제공됩니다. 기본값입니다.
AssumeUniversal 오프셋 값이 input 필요하지 않은 경우 format 반환 DateTimeOffset 된 개체에 UTC 오프셋(+00:00)이 제공됩니다.
AllowInnerWhite input 의해 format지정되지 않은 내부 공백을 포함할 수 있습니다. 날짜 및 시간 구성 요소와 개별 구성 요소 사이에 추가 공백이 표시될 수 있으며 문자열을 구문 분석할 때 무시됩니다.
AllowLeadingWhite input 지정되지 않은 선행 공백을 format포함할 수 있습니다. 문자열을 구문 분석할 때 무시됩니다.
AllowTrailingWhite input 의해 format지정되지 않은 후행 공백을 포함할 수 있습니다. 문자열을 구문 분석할 때 무시됩니다.
AllowWhiteSpaces input 지정되지 않은 선행, 후행 및 내부 공백을 format포함할 수 있습니다. 문자열을 구문 분석할 때 지정 format 되지 않은 추가 공백 문자는 모두 무시됩니다.
None 에서 추가 공백이 허용되지 않음을 input나타냅니다. 공백은 에 지정된 format대로 정확하게 표시되어야 합니다. 기본 동작입니다.
RoundtripKind 구조체에 속성이 DateTimeOffset 포함되어 Kind 있지 않으므로 아무런 효과가 없습니다.

호출자 참고

.NET Framework 4 ParseExact 에서는 구문 분석할 문자열에 시간 구성 요소와 규약이 없는 AM/PM 지정자가 포함된 경우 메서드가 throw FormatException 됩니다. .NET Framework 3.5 이전 버전에서는 AM/PM 지정자가 무시됩니다.

추가 정보

적용 대상

ParseExact(String, String, IFormatProvider)

지정된 형식 및 문화권별 형식 정보를 사용하여 날짜 및 시간의 지정된 문자열 표현을 해당 DateTimeOffset으로 변환합니다. 문자열 표현의 형식이 지정된 형식과 정확하게 일치해야 합니다.

public:
 static DateTimeOffset ParseExact(System::String ^ input, System::String ^ format, IFormatProvider ^ formatProvider);
public static DateTimeOffset ParseExact (string input, string format, IFormatProvider formatProvider);
public static DateTimeOffset ParseExact (string input, string format, IFormatProvider? formatProvider);
static member ParseExact : string * string * IFormatProvider -> DateTimeOffset
Public Shared Function ParseExact (input As String, format As String, formatProvider As IFormatProvider) As DateTimeOffset

매개 변수

input
String

변환할 날짜 및 시간이 포함된 문자열입니다.

format
String

input의 예상 형식을 정의하는 형식 지정자입니다.

formatProvider
IFormatProvider

input에 대한 문화권별 형식 지정 정보를 제공하는 개체입니다.

반환

DateTimeOffset

formatformatProvider에 의해 지정된 대로 input에 포함된 날짜 및 시간과 같은 개체입니다.

예외

오프셋이 14시간보다 크거나 -14시간보다 작습니다.

input이(가) null인 경우

또는

format이(가) null인 경우

input가 빈 문자열("")인 경우

또는

input에 날짜 및 시간의 유효한 문자열 표현이 없습니다.

또는

format이 빈 문자열인 경우

또는

input의 시간 구성 요소와 AM/PM 지정자가 일치하지 않습니다.

예제

다음 예제에서는 표준 및 사용자 지정 형식 지정자와 고정 문화권이 있는 메서드를 사용하여 DateTimeOffset.ParseExact(String, String, IFormatProvider) 여러 날짜 및 시간 문자열을 구문 분석합니다.

string dateString, format;
DateTimeOffset result;
CultureInfo provider = CultureInfo.InvariantCulture;

// Parse date-only value with invariant culture.
dateString = "06/15/2008";
format = "d";
try
{
   result = DateTimeOffset.ParseExact(dateString, format, provider);
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
   Console.WriteLine("{0} is not in the correct format.", dateString);
}

// Parse date-only value without leading zero in month using "d" format.
// Should throw a FormatException because standard short date pattern of
// invariant culture requires two-digit month.
dateString = "6/15/2008";
try
{
   result = DateTimeOffset.ParseExact(dateString, format, provider);
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
   Console.WriteLine("{0} is not in the correct format.", dateString);
}

// Parse date and time with custom specifier.
dateString = "Sun 15 Jun 2008 8:30 AM -06:00";
format = "ddd dd MMM yyyy h:mm tt zzz";
try
{
   result = DateTimeOffset.ParseExact(dateString, format, provider);
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
   Console.WriteLine("{0} is not in the correct format.", dateString);
}

// Parse date and time with offset without offset//s minutes.
// Should throw a FormatException because "zzz" specifier requires leading
// zero in hours.
dateString = "Sun 15 Jun 2008 8:30 AM -06";
try
{
   result = DateTimeOffset.ParseExact(dateString, format, provider);
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
   Console.WriteLine("{0} is not in the correct format.", dateString);
}
// The example displays the following output:
//    06/15/2008 converts to 6/15/2008 12:00:00 AM -07:00.
//    6/15/2008 is not in the correct format.
//    Sun 15 Jun 2008 8:30 AM -06:00 converts to 6/15/2008 8:30:00 AM -06:00.
//    Sun 15 Jun 2008 8:30 AM -06 is not in the correct format.
let provider = CultureInfo.InvariantCulture

// Parse date-only value with invariant culture.
let dateString = "06/15/2008"
let format = "d"
try
    let result = DateTimeOffset.ParseExact(dateString, format, provider)
    printfn $"{dateString} converts to {result}."
with :? FormatException ->
    printfn $"{dateString} is not in the correct format."

// Parse date-only value without leading zero in month using "d" format.
// Should throw a FormatException because standard short date pattern of
// invariant culture requires two-digit month.
let dateString = "6/15/2008"
try
    let result = DateTimeOffset.ParseExact(dateString, format, provider)
    printfn $"{dateString} converts to {result}."
with :? FormatException ->
    printfn $"{dateString} is not in the correct format."

// Parse date and time with custom specifier.
let dateString = "Sun 15 Jun 2008 8:30 AM -06:00"
let format = "ddd dd MMM yyyy h:mm tt zzz"
try
    let result = DateTimeOffset.ParseExact(dateString, format, provider)
    printfn $"{dateString} converts to {result}."
with :? FormatException ->
    printfn $"{dateString} is not in the correct format."

// Parse date and time with offset without offset//s minutes.
// Should throw a FormatException because "zzz" specifier requires leading
// zero in hours.
let dateString = "Sun 15 Jun 2008 8:30 AM -06"
try
    let result = DateTimeOffset.ParseExact(dateString, format, provider)
    printfn $"{dateString} converts to {result}."
with :? FormatException ->
    printfn $"{dateString} is not in the correct format."

// The example displays the following output:
//    06/15/2008 converts to 6/15/2008 12:00:00 AM -07:00.
//    6/15/2008 is not in the correct format.
//    Sun 15 Jun 2008 8:30 AM -06:00 converts to 6/15/2008 8:30:00 AM -06:00.
//    Sun 15 Jun 2008 8:30 AM -06 is not in the correct format.
Dim dateString, format As String  
Dim result As DateTimeOffset
Dim provider As CultureInfo = CultureInfo.InvariantCulture

' Parse date-only value with invariant culture.
dateString = "06/15/2008"
format = "d"
Try
   result = DateTimeOffset.ParseExact(dateString, format, provider)
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString())
Catch e As FormatException
   Console.WriteLine("{0} is not in the correct format.", dateString)
End Try 

' Parse date-only value without leading zero in month using "d" format.
' Should throw a FormatException because standard short date pattern of 
' invariant culture requires two-digit month.
dateString = "6/15/2008"
Try
   result = DateTimeOffset.ParseExact(dateString, format, provider)
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString())
Catch e As FormatException
   Console.WriteLine("{0} is not in the correct format.", dateString)
End Try 

' Parse date and time with custom specifier.
dateString = "Sun 15 Jun 2008 8:30 AM -06:00"
format = "ddd dd MMM yyyy h:mm tt zzz"        
Try
   result = DateTimeOffset.ParseExact(dateString, format, provider)
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString())
Catch e As FormatException
   Console.WriteLine("{0} is not in the correct format.", dateString)
End Try 

' Parse date and time with offset without offset's minutes.
' Should throw a FormatException because "zzz" specifier requires leading  
' zero in hours.
dateString = "Sun 15 Jun 2008 8:30 AM -06"
Try
   result = DateTimeOffset.ParseExact(dateString, format, provider)
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString())
Catch e As FormatException
   Console.WriteLine("{0} is not in the correct format.", dateString)
End Try 
' The example displays the following output:
'    06/15/2008 converts to 6/15/2008 12:00:00 AM -07:00.
'    6/15/2008 is not in the correct format.
'    Sun 15 Jun 2008 8:30 AM -06:00 converts to 6/15/2008 8:30:00 AM -06:00.
'    Sun 15 Jun 2008 8:30 AM -06 is not in the correct format.

다음 예제에서는 ISO 8601을 준수해야 하는 문자열 배열을 구문 분석합니다. 예제의 출력에서와 같이 선행 또는 후행 공백이 있는 문자열은 범위를 벗어난 날짜 및 시간 요소가 있는 문자열과 마찬가지로 성공적으로 구문 분석하지 못합니다.

module parseexact_iso8601

open System

let dateStrings =
    [ "2018-08-18T12:45:16.0000000Z"
      "2018/08/18T12:45:16.0000000Z"
      "2018-18-08T12:45:16.0000000Z"
      " 2018-08-18T12:45:16.0000000Z "
      "2018-08-18T12:45:16.0000000+02:00"
      "2018-08-18T12:45:16.0000000-07:00" ]

for dateString in dateStrings do
    try
        let date =
            DateTimeOffset.ParseExact(dateString, "O", null)

        printfn $"""{dateString, -35} --> {date.ToString "yyyy-MM-dd HH:mm:ss.FF zzz"}"""
    with :? FormatException -> printfn $"FormatException: Unable to convert '{dateString}'"


// The example displays the following output:
//      2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//      FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//      FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//      FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//      2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//      2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
using System;

public class Example2
{
   public static void Main()
   {
      string[] dateStrings = { "2018-08-18T12:45:16.0000000Z",
                               "2018/08/18T12:45:16.0000000Z",
                               "2018-18-08T12:45:16.0000000Z",
                               " 2018-08-18T12:45:16.0000000Z ",
                               "2018-08-18T12:45:16.0000000+02:00",
                               "2018-08-18T12:45:16.0000000-07:00" }; 
      
      foreach (var dateString in dateStrings)
      {
         try {
            var date = DateTimeOffset.ParseExact(dateString, "O", null);
            Console.WriteLine($"{dateString,-35} --> {date:yyyy-MM-dd HH:mm:ss.FF zzz}");
         }
         catch (FormatException)
         {
            Console.WriteLine($"FormatException: Unable to convert '{dateString}'");
         }   
      } 
   }
}
// The example displays the following output:
//      2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
//      FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
//      FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
//      FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
//      2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
//      2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00
Public Module Example
   Public Sub Main()
      Dim dateStrings() As String = { "2018-08-18T12:45:16.0000000Z",
                                      "2018/08/18T12:45:16.0000000Z",
                                      "2018-18-08T12:45:16.0000000Z",
                                      " 2018-08-18T12:45:16.0000000Z ",
                                      "2018-08-18T12:45:16.0000000+02:00",
                                      "2018-08-18T12:45:16.0000000-07:00" } 
      
      For Each dateStr In dateStrings
         Try 
            Dim dat = DateTimeOffset.ParseExact(dateStr, "O", Nothing)
            Console.WriteLine($"{dateStr,-35} --> {dat:yyyy-MM-dd HH:mm:ss.FF zzz}")
         Catch  e As FormatException
            Console.WriteLine($"FormatException: Unable to convert '{dateStr}'")
         End Try   
      Next 
   End Sub
End Module
' The example displays the following output:
'      2018-08-18T12:45:16.0000000Z        --> 2018-08-18 12:45:16 +00:00
'      FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z'
'      FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z'
'      FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z '
'      2018-08-18T12:45:16.0000000+02:00   --> 2018-08-18 12:45:16 +02:00
'      2018-08-18T12:45:16.0000000-07:00   --> 2018-08-18 12:45:16 -07:00

설명

이 메서드는 ParseExact(String, String, IFormatProvider) 매개 변수로 정의된 형식이어야 하는 날짜의 문자열 표현을 format 구문 분석합니다. 또한 날짜 및 시간의 문자열 표현에 대한 요소<Time>와 해당 요소가 지정한 format순서대로 나타나야 합니다<Date><Offset>. 문자열이 inputformat 매개 변수와 일치하지 않으면 메서드는 .를 FormatExceptionthrow합니다. 반면, 메서드는 DateTimeOffset.Parse(String, IFormatProvider) 형식 공급자의 개체에서 인식되는 형식 중 하나로 날짜의 DateTimeFormatInfo 문자열 표현을 구문 분석합니다. Parse에서는 <Date><Time>날짜 및 시간의 문자열 표현 및 <Offset> 요소를 순서에 따라 표시할 수도 있습니다.

format 매개 변수는 매개 변수의 필수 input 형식을 정의하는 단일 표준 형식 지정자 또는 하나 이상의 사용자 지정 형식 지정자를 포함하는 문자열입니다. 유효한 서식 코드에 대한 자세한 내용은 표준 날짜 및 시간 형식 문자열 및 사용자 지정 날짜 및 시간 형식 문자열을 참조하세요. 오프셋이 z``zz``zzz 있어야 input함을 나타내는 사용자 지정 형식 지정자를 포함하는 경우 format 해당 오프셋에는 음수 기호 또는 양수 기호가 포함되어야 합니다. 기호가 없으면 메서드가 을 throw합니다 FormatException.

시간이 아닌 날짜를 포함해야 하는 input 경우 format 결과 DateTimeOffset 개체에 자정(0:00:00)의 시간이 할당됩니다. 날짜가 아닌 시간을 포함해야 하는 input 경우 format 결과 DateTimeOffset 개체에 로컬 시스템의 현재 날짜가 할당됩니다. 오프셋을 input 포함하지 않아도 되는 경우 format 결과 DateTimeOffset 개체에 로컬 시스템의 표준 시간대 오프셋이 할당됩니다.

사용되는 특정 날짜 및 시간 기호와 문자열 input 은 매개 변수에 의해 formatProvider 정의되며, if의 input format 정확한 형식은 표준 형식 지정자 문자열입니다. 매개 변수는 formatProvider 다음 중 하나일 수 있습니다.

nullCultureInfo 경우 formatprovider 현재 문화권에 해당하는 개체가 사용됩니다.

호출자 참고

.NET Framework 4 ParseExact 에서는 구문 분석할 문자열에 시간 구성 요소와 규약이 없는 AM/PM 지정자가 포함된 경우 메서드가 throw FormatException 됩니다. .NET Framework 3.5 이전 버전에서는 AM/PM 지정자가 무시됩니다.

추가 정보

적용 대상

ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles)

지정된 형식, 문화권별 형식 정보 및 스타일을 사용하여 날짜 및 시간을 나타내는 문자 범위를 해당 DateTimeOffset으로 변환합니다. 날짜 및 시간 표현의 형식이 지정된 형식과 정확하게 일치해야 합니다.

public static DateTimeOffset ParseExact (ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles = System.Globalization.DateTimeStyles.None);
public static DateTimeOffset ParseExact (ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles = System.Globalization.DateTimeStyles.None);
static member ParseExact : ReadOnlySpan<char> * ReadOnlySpan<char> * IFormatProvider * System.Globalization.DateTimeStyles -> DateTimeOffset
Public Shared Function ParseExact (input As ReadOnlySpan(Of Char), format As ReadOnlySpan(Of Char), formatProvider As IFormatProvider, Optional styles As DateTimeStyles = System.Globalization.DateTimeStyles.None) As DateTimeOffset

매개 변수

input
ReadOnlySpan<Char>

날짜 및 시간을 나타내는 문자 범위입니다.

format
ReadOnlySpan<Char>

input의 예상 형식을 정의하는 형식 지정자를 포함하는 문자 범위입니다.

formatProvider
IFormatProvider

input에 대한 문화권별 서식 정보를 제공하는 개체입니다.

styles
DateTimeStyles

input에 사용할 수 있는 형식을 나타내는 열거형 값의 비트 조합입니다.

반환

DateTimeOffset

format, formatProviderstyles 매개 변수에 의해 지정된 대로 input 매개 변수에 포함된 날짜 및 시간과 같은 개체입니다.

예외

오프셋이 14시간보다 크거나 -14시간보다 작습니다. -또는- 매개 변수에는 styles 지원되지 않는 값이 포함됩니다. -또는- 매개 변수에 styles DateTimeStyles 함께 사용할 수 없는 값이 포함되어 있습니다.

input은 비어 있는 문자 범위입니다. 또는 input에 날짜 및 시간의 유효한 문자열 표현이 없습니다. 또는 format은 비어 있는 문자 범위입니다. -또는- 시간 구성 요소 및 AM/PM 지정자가 input 동의하지 않습니다.

설명

이 메서드는 매개 변수에서 정의 format 한 형식이어야 하는 날짜를 나타내는 문자 범위를 구문 분석합니다. 또한 날짜 및 시간의 문자열 표현에 대한 , 및 요소가 지정된 format순서대로 표시되어야 합니다<Date>.<Offset> <Time> input 패턴과 format 일치하지 않으면 메서드가 .를 FormatExceptionthrow합니다. 반면, 메서드는 DateTimeOffset.Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) 형식 공급자의 개체에서 인식되는 형식 중 하나로 날짜의 DateTimeFormatInfo 문자열 표현을 구문 분석합니다. Parse에서는 <Date><Time>날짜 및 시간의 문자열 표현 및 <Offset> 요소를 순서에 따라 표시할 수도 있습니다.

매개 변수는 format 단일 문자 표준 형식 지정자 또는 매개 변수의 input 필수 형식을 정의하는 하나 이상의 사용자 지정 형식 지정자를 포함하는 문자 범위입니다. 유효한 서식 코드에 대한 자세한 내용은 표준 날짜 및 시간 형식 문자열 및 사용자 지정 날짜 및 시간 형식 문자열을 참조하세요. 오프셋이 z``zz``zzz 있어야 input함을 나타내는 사용자 지정 형식 지정자를 포함하는 경우 format 해당 오프셋에는 음수 기호 또는 양수 기호가 포함되어야 합니다. 기호가 없으면 메서드가 을 throw합니다 FormatException.

시간이 아닌 날짜를 포함해야 하는 input 경우 format 결과 DateTimeOffset 개체에 자정(0:00:00)의 시간이 할당됩니다. 날짜가 아닌 시간을 포함해야 하는 input 경우 format 결과 DateTimeOffset 개체에 로컬 시스템의 현재 날짜가 할당됩니다. 오프셋을 input 포함하지 않아도 되는 경우 format 결과 DateTimeOffset 개체에 로컬 시스템의 표준 시간대 오프셋이 할당됩니다.

사용된 특정 날짜 및 시간 기호 및 문자열 input 은 매개 변수에 의해 formatProvider 정의되며, if의 input format 정확한 형식은 표준 형식 지정자입니다. 매개 변수는 formatProvider 다음 중 하나일 수 있습니다.

nullCultureInfo 경우 formatprovider 현재 문화권에 해당하는 개체가 사용됩니다.

적용 대상

ParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles)

지정된 형식, 문화권별 형식 정보 및 스타일을 사용하여 지정된 날짜와 시간의 문자열 표현을 해당 DateTimeOffset으로 변환합니다. 날짜 및 시간 표현의 형식은 지정된 형식 중 하나와 정확히 일치해야 합니다.

public static DateTimeOffset ParseExact (ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles = System.Globalization.DateTimeStyles.None);
public static DateTimeOffset ParseExact (ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles = System.Globalization.DateTimeStyles.None);
static member ParseExact : ReadOnlySpan<char> * string[] * IFormatProvider * System.Globalization.DateTimeStyles -> DateTimeOffset
Public Shared Function ParseExact (input As ReadOnlySpan(Of Char), formats As String(), formatProvider As IFormatProvider, Optional styles As DateTimeStyles = System.Globalization.DateTimeStyles.None) As DateTimeOffset

매개 변수

input
ReadOnlySpan<Char>

변환할 날짜 및 시간을 포함하는 문자 범위입니다.

formats
String[]

input의 예상 형식을 정의하는 형식 지정자의 배열입니다.

formatProvider
IFormatProvider

input에 대한 문화권별 형식 지정 정보를 제공하는 개체입니다.

styles
DateTimeStyles

input에 사용할 수 있는 형식을 나타내는 열거형 값의 비트 조합입니다.

반환

DateTimeOffset

formats, formatProviderstyles 매개 변수에 의해 지정된 대로 input 매개 변수에 포함된 날짜 및 시간과 같은 개체입니다.

예외

오프셋이 14시간보다 크거나 -14시간보다 작습니다. 또는 styles에 지원되지 않는 값이 포함되어 있습니다. -또는- 매개 변수에 styles DateTimeStyles 함께 사용할 수 없는 값이 포함되어 있습니다.

input은 비어 있는 문자 범위입니다. 또는 input에 날짜 및 시간의 유효한 문자열 표현이 없습니다. -또는- 유효한 형식 지정자를 포함하는 요소가 formats 없습니다. -또는- 시간 구성 요소 및 AM/PM 지정자가 input 동의하지 않습니다.

설명

이 메서드는 매개 변수에 할당된 formats 패턴 중 하나와 일치하는 날짜를 나타내는 문자 범위를 구문 분석합니다. input 이러한 패턴 중 하나와 매개 변수에서 정의 styles 한 변형 중 하나와 일치하지 않으면 메서드가 을 throw합니다FormatException. 여러 서식 패턴과 비교하는 input 것 외에도 이 오버로드는 메서드와 동일하게 DateTimeOffset.ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) 동작합니다.

formats 매개 변수는 단일 표준 형식 지정자 또는 매개 변수의 input 가능한 패턴을 정의하는 하나 이상의 사용자 지정 형식 지정자를 포함하는 문자열 배열입니다. 메서드가 호출 input 되면 이러한 패턴 중 하나와 일치해야 합니다. 유효한 서식 코드에 대한 자세한 내용은 표준 날짜 및 시간 형식 문자열 및 사용자 지정 날짜 및 시간 형식 문자열을 참조하세요. 일치하는 요소에 formats 오프셋이 있어야 input함을 나타내는 사용자 지정 형식 지정자가 포함된 z``zz``zzz 경우 해당 오프셋에는 음수 기호 또는 양수 기호가 포함되어야 합니다. 기호가 없으면 메서드가 을 throw합니다 FormatException.

중요

formats 이 오버로드의 매개 변수를 사용하여 여러 형식을 지정하면 많은 사용자가 날짜와 시간을 입력할 때 발생하는 불만을 줄일 수 있습니다. 특히 여러 개의 입력된 패턴을 정의 하는 기능 포함 하거나 부족 한 월, 일, 시간, 분 및 초를 앞에 오는 0 수 있는 날짜와 시간 표현을 처리 하도록 애플리케이션을 수 있습니다.

일치하는 요소에 formats 날짜가 input 포함되어야 하지만 시간이 없는 경우 결과 DateTimeOffset 개체에 자정(0:00:00)의 시간이 할당됩니다. 일치하는 요소에 formats input 시간이 포함되어야 하지만 날짜가 아닌 경우 결과 DateTimeOffset 개체에 로컬 시스템의 현재 날짜가 할당됩니다. 일치하는 요소가 formats 오프셋을 input 포함하지 않아도 되는 경우 결과 DateTimeOffset 개체의 오프셋은 매개 변수 값 styles 에 따라 달라집니다. 포함된 AssumeLocal경우 styles 로컬 표준 시간대의 오프셋이 개체에 DateTimeOffset 할당됩니다. 포함된 AssumeUniversal경우 styles UTC(협정 세계시) 오프셋 또는 +00:00이 개체에 DateTimeOffset 할당됩니다. 두 값을 모두 지정하지 않으면 현지 표준 시간대의 오프셋이 사용됩니다.

사용된 input 특정 날짜 및 시간 기호 및 문자열은 매개 변수에 formatProvider 의해 정의됩니다. 일치하는 요소가 표준 형식 지정자 문자열인 경우 정확한 형식 input에도 formats 마찬가지입니다. 매개 변수는 formatProvider 다음 중 하나일 수 있습니다.

nullCultureInfo 경우 formatprovider 현재 문화권에 해당하는 개체가 사용됩니다.

매개 변수는 styles 입력 문자열에 공백이 허용되는지 여부를 정의하고 명시적 오프셋 구성 요소가 없는 문자열을 구문 분석하는 방법을 나타내며 구문 분석 작업의 일부로 UTC 변환을 지원합니다. 를 제외한 NoCurrentDateDefault열거형의 DateTimeStyles 모든 멤버가 지원됩니다. 다음 표에서는 지원되는 각 멤버의 효과를 나열합니다.

DateTimeStyles 멤버 동작
AdjustToUniversal input 구문 분석하고 필요한 경우 UTC로 변환합니다. 문자열을 구문 분석한 다음 반환 DateTimeOffset 된 개체의 메서드를 호출하는 DateTimeOffset.ToUniversalTime 것과 같습니다.
AssumeLocal 일치하는 요소에 formats 오프셋 값이 input 필요하지 않으면 반환 DateTimeOffset 된 개체에 현지 표준 시간대의 오프셋이 지정됩니다. 기본값입니다.
AssumeUniversal 일치하는 요소에 formats 오프셋 값이 input 필요하지 않으면 반환 DateTimeOffset 된 개체에 UTC 오프셋(+00:00)이 지정됩니다.
AllowInnerWhite input 의해 format지정되지 않은 내부 공백을 포함할 수 있습니다. 추가 공백은 날짜 및 시간 구성 요소와 개별 구성 요소(오프셋 제외) 내에 표시될 수 있으며 문자열을 구문 분석할 때 무시됩니다.
AllowLeadingWhite input 지정되지 않은 선행 공백을 formats포함할 수 있습니다. 문자열을 구문 분석할 때 무시됩니다.
AllowTrailingWhite input 의해 formats지정되지 않은 후행 공백을 포함할 수 있습니다. 문자열을 구문 분석할 때 무시됩니다.
AllowWhiteSpaces input 지정되지 않은 선행, 후행 및 내부 공백을 formats포함할 수 있습니다. 문자열을 구문 분석할 때 일치하는 요소에 formats 지정되지 않은 추가 공백 문자는 모두 무시됩니다.
None 에서 추가 공백이 허용되지 않음을 input나타냅니다. 공백은 일치가 발생하려면 특정 요소 formats 에 지정된 대로 정확하게 표시되어야 합니다. 기본 동작입니다.
RoundtripKind 구조체에 속성이 DateTimeOffset 포함되어 Kind 있지 않으므로 아무런 효과가 없습니다.

적용 대상