DateTimeOffset.TryParse 메서드

정의

날짜와 시간에 대한 지정된 문자열 표현을 해당 DateTimeOffset으로 변환합니다.

오버로드

TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset)

날짜 및 시간에 대한 지정된 문자열 표현을 해당 DateTimeOffset 요소로 변환하고, 변환에 성공했는지를 나타내는 값을 반환합니다.

TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset)

날짜 및 시간의 지정된 범위 표현을 해당 DateTimeOffset 요소로 변환하고, 변환에 성공했는지 여부를 나타내는 값을 반환하려고 시도합니다.

TryParse(String, IFormatProvider, DateTimeOffset)

문자열을 값으로 구문 분석하려고 시도합니다.

TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeOffset)

문자 범위를 값으로 구문 분석하려고 시도합니다.

TryParse(ReadOnlySpan<Char>, DateTimeOffset)

날짜 및 시간의 지정된 범위 표현을 해당 DateTimeOffset 요소로 변환하고, 변환에 성공했는지 여부를 나타내는 값을 반환하려고 시도합니다.

TryParse(String, DateTimeOffset)

날짜와 시간에 대한 지정된 문자열 표현을 해당 DateTimeOffset 요소로 변환하고, 변환에 성공했는지를 나타내는 값을 반환합니다.

TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

날짜 및 시간에 대한 지정된 문자열 표현을 해당 DateTimeOffset 요소로 변환하고, 변환에 성공했는지를 나타내는 값을 반환합니다.

public:
 static bool TryParse(System::String ^ input, IFormatProvider ^ formatProvider, System::Globalization::DateTimeStyles styles, [Runtime::InteropServices::Out] DateTimeOffset % result);
public static bool TryParse (string input, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles, out DateTimeOffset result);
public static bool TryParse (string? input, IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles, out DateTimeOffset result);
static member TryParse : string * IFormatProvider * System.Globalization.DateTimeStyles * DateTimeOffset -> bool
Public Shared Function TryParse (input As String, formatProvider As IFormatProvider, styles As DateTimeStyles, ByRef result As DateTimeOffset) As Boolean

매개 변수

input
String

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

formatProvider
IFormatProvider

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

styles
DateTimeStyles

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

result
DateTimeOffset

메서드가 반환될 때 변환에 성공한 경우 의 input날짜 및 시간에 해당하는 값을 포함하거나 변환에 실패한 경우 DateTimeOffset.MinValue 값을 포함합니다DateTimeOffset. input 매개 변수가 null이거나 날짜 및 시간에 대한 유효한 문자열 표현을 포함하고 있지 않으면 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다.

반환

input 매개 변수가 변환되었으면 true이고, 변환되지 않았으면 false입니다.

예외

styles에 정의되지 않은 DateTimeStyles 값이 들어 있습니다.

또는

NoCurrentDateDefault은 지원되지 않습니다.

또는

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

예제

다음 예제에서는 다양한 DateTimeStyles 값으로 메서드를 호출 TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset) 하여 다양한 날짜 및 시간 형식으로 일부 문자열을 구문 분석합니다.

string dateString;
DateTimeOffset parsedDate;

dateString = "05/01/2008 6:00:00";
// Assume time is local
if (DateTimeOffset.TryParse(dateString, null as IFormatProvider,
                            DateTimeStyles.AssumeLocal,
                            out parsedDate))
   Console.WriteLine("'{0}' was converted to {1}.",
                     dateString, parsedDate.ToString());
else
   Console.WriteLine("Unable to parse '{0}'.", dateString);

// Assume time is UTC
if (DateTimeOffset.TryParse(dateString, null as IFormatProvider,
                            DateTimeStyles.AssumeUniversal,
                            out parsedDate))
   Console.WriteLine("'{0}' was converted to {1}.",
                     dateString, parsedDate.ToString());
else
   Console.WriteLine("Unable to parse '{0}'.", dateString);

// Parse and convert to UTC
dateString = "05/01/2008 6:00:00AM +5:00";
if (DateTimeOffset.TryParse(dateString, null as IFormatProvider,
                           DateTimeStyles.AdjustToUniversal,
                           out parsedDate))
   Console.WriteLine("'{0}' was converted to {1}.",
                     dateString, parsedDate.ToString());
else
   Console.WriteLine("Unable to parse '{0}'.", dateString);
// The example displays the following output to the console:
//    '05/01/2008 6:00:00' was converted to 5/1/2008 6:00:00 AM -07:00.
//    '05/01/2008 6:00:00' was converted to 5/1/2008 6:00:00 AM +00:00.
//    '05/01/2008 6:00:00AM +5:00' was converted to 5/1/2008 1:00:00 AM +00:00.
let dateString = "05/01/2008 6:00:00"
// Assume time is local
match DateTimeOffset.TryParse(dateString, null, DateTimeStyles.AssumeLocal) with
| true, parsedDate ->
    printfn $"'{dateString}' was converted to {parsedDate}."
| _ ->
    printfn $"Unable to parse '{dateString}'."

// Assume time is UTC
match DateTimeOffset.TryParse(dateString, null, DateTimeStyles.AssumeUniversal) with
| true, parsedDate ->
    printfn $"'{dateString}' was converted to {parsedDate}."
| _ ->
    printfn $"Unable to parse '{dateString}'."

// Parse and convert to UTC
let dateString = "05/01/2008 6:00:00AM +5:00"
match DateTimeOffset.TryParse(dateString, null, DateTimeStyles.AdjustToUniversal) with
| true, parsedDate ->
    printfn $"'{dateString}' was converted to {parsedDate}."
| _ ->
    printfn $"Unable to parse '{dateString}'."

// The example displays the following output to the console:
//    '05/01/2008 6:00:00' was converted to 5/1/2008 6:00:00 AM -07:00.
//    '05/01/2008 6:00:00' was converted to 5/1/2008 6:00:00 AM +00:00.
//    '05/01/2008 6:00:00AM +5:00' was converted to 5/1/2008 1:00:00 AM +00:00.
Dim dateString As String
Dim parsedDate As DateTimeOffset

dateString = "05/01/2008 6:00:00"
' Assume time is local 
If DateTimeOffset.TryParse(dateString, Nothing, _
                           DateTimeStyles.AssumeLocal, _
                           parsedDate) Then
   Console.WriteLine("'{0}' was converted to {1}.", _
                     dateString, parsedDate.ToString())
Else
   Console.WriteLine("Unable to parse '{0}'.", dateString)    
End If

' Assume time is UTC
If DateTimeOffset.TryParse(dateString, Nothing, _
                           DateTimeStyles.AssumeUniversal, _
                           parsedDate) Then
   Console.WriteLine("'{0}' was converted to {1}.", _
                     dateString, parsedDate.ToString())
Else
   Console.WriteLine("Unable to parse '{0}'.", dateString)    
End If

' Parse and convert to UTC 
dateString = "05/01/2008 6:00:00AM +5:00"
If DateTimeOffset.TryParse(dateString, Nothing, _
                           DateTimeStyles.AdjustToUniversal, _
                           parsedDate) Then
   Console.WriteLine("'{0}' was converted to {1}.", _
                     dateString, parsedDate.ToString())
Else
   Console.WriteLine("Unable to parse '{0}'.", dateString)    
End If
' The example displays the following output to the console:
'    '05/01/2008 6:00:00' was converted to 5/1/2008 6:00:00 AM -07:00.
'    '05/01/2008 6:00:00' was converted to 5/1/2008 6:00:00 AM +00:00.
'    '05/01/2008 6:00:00AM +5:00' was converted to 5/1/2008 1:00:00 AM +00:00.

설명

메서드의 TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset) 이 오버로드는 변환이 DateTimeOffset.Parse(String, IFormatProvider, DateTimeStyles) 실패할 경우 예외를 throw하지 않는다는 점을 제외하고 메서드와 같습니다. 메서드는 임의의 순서로 표시할 수 있고 공백으로 구분되는 세 개의 요소로 문자열을 구문 분석합니다. 이러한 세 가지 요소는 다음 표에 나와 있습니다.

요소 예제
<Date> "2/10/2007"
<Time> "오후 1:02:03"
<Offset> "-7:30"

이러한 각 요소는 선택 사항이지만 오프 <셋> 은 단독으로 표시할 수 없습니다. 날짜> 또는 <시간과> 함께 <제공해야 합니다. Date>가 없으면 <기본값은 현재 날짜입니다. Date>가 있지만 해당 연도 구성 요소가 두 자리 숫자로만 구성된 경우 <속성 값 Calendar.TwoDigitYearMax 에 따라 매개 변수의 현재 달력에서 provider 1년으로 변환됩니다. Time>이 누락된 경우 <기본값은 오전 12:00:00입니다. Offset>이 누락된 경우 <기본값은 로컬 표준 시간대의 오프셋이거나 Zero 또는 DateTimeStyles.AssumeUniversal 값이 DateTimeStyles.AdjustToUniversalstyles지정된 경우 입니다. Offset>이 있는 경우 <UTC(협정 세계시)의 음수 또는 양수 오프셋을 나타낼 수 있습니다. 두 경우 모두 Offset>에는 <기호 기호가 포함되어야 합니다. 그렇지 않으면 메서드가 를 반환합니다false.

문자열은 input 매개 변수에서 제공하는 formatProvider 개체의 문화권별 서식 정보를 DateTimeFormatInfo 사용하여 구문 분석됩니다. 매개 변수는 formatProvider 다음 중 하나일 수 있습니다.

또한 각 요소는 선행 또는 후행 공백으로 구분할 수 있으며 <날짜> 및 <시간> 구성 요소에는 내부 공백(예: 6: 00:00)이 포함될 수 있습니다. <오프셋> 구성 요소만 내부 공백을 포함할 수 없습니다.

가 이 nullCultureInfoprovider 현재 문화권에 해당하는 개체가 사용됩니다.

Offset>에 <사용되는 양수 또는 음수 기호는 + 또는 -이어야 합니다. 매개 변수 NumberFormat 의 속성에서 PositiveSign 반환된 개체의 NumberFormatInfo 또는 NegativeSign 속성에 formatprovider 의해 정의되지 않습니다.

열거형의 DateTimeStyles 다음 멤버가 지원됩니다.

DateTimeStyles 멤버 의견
AdjustToUniversal 가 나타내는 input 문자열을 구문 분석하고 필요한 경우 UTC로 변환합니다. 문자열을 구문 분석한 다음 반환된 개체의 ToUniversalTime() 메서드를 호출하는 것과 같습니다.
AllowInnerWhite 유효하지만 이 값은 무시됩니다. 내부 공백은 날짜> 및 <시간> 구성 요소에서 <허용됩니다.
AllowLeadingWhite 유효하지만 이 값은 무시됩니다. 선행 공백은 구문 분석된 문자열의 각 구성 요소 앞에 허용됩니다.
AllowTrailingWhite 유효하지만 이 값은 무시됩니다. 후행 공백은 구문 분석된 문자열의 각 구성 요소 앞에 허용됩니다.
AllowWhiteSpaces 기본 동작입니다. 와 같은 DateTimeStyles.None보다 제한적인 DateTimeStyles 열거형 값을 제공하여 재정의할 수 없습니다.
AssumeLocal 매개 변수에 input Offset> 요소가 없는 <경우 로컬 표준 시간대의 오프셋이 제공되어야 했음을 나타냅니다. 메서드의 기본 동작입니다 TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset) .
AssumeUniversal 매개 변수에 input Offset> 요소가 없는 <경우 UTC 오프셋(00:00)을 제공해야 했음을 나타냅니다.
None 유효하지만 이 값은 무시되며 아무런 영향을 주지 않습니다.
RoundtripKind 구조체에 DateTimeOffset 속성이 Kind 포함되어 있지 않으므로 이 값은 영향을 주지 않습니다.

DateTimeStyles.NoCurrentDateDefault 값만 지원되지 않습니다. ArgumentException 이 값이 매개 변수에 styles 포함되면 이 throw됩니다.

추가 정보

적용 대상

TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

날짜 및 시간의 지정된 범위 표현을 해당 DateTimeOffset 요소로 변환하고, 변환에 성공했는지 여부를 나타내는 값을 반환하려고 시도합니다.

public:
 static bool TryParse(ReadOnlySpan<char> input, IFormatProvider ^ formatProvider, System::Globalization::DateTimeStyles styles, [Runtime::InteropServices::Out] DateTimeOffset % result);
public static bool TryParse (ReadOnlySpan<char> input, IFormatProvider? formatProvider, System.Globalization.DateTimeStyles styles, out DateTimeOffset result);
public static bool TryParse (ReadOnlySpan<char> input, IFormatProvider formatProvider, System.Globalization.DateTimeStyles styles, out DateTimeOffset result);
static member TryParse : ReadOnlySpan<char> * IFormatProvider * System.Globalization.DateTimeStyles * DateTimeOffset -> bool
Public Shared Function TryParse (input As ReadOnlySpan(Of Char), formatProvider As IFormatProvider, styles As DateTimeStyles, ByRef result As DateTimeOffset) As Boolean

매개 변수

input
ReadOnlySpan<Char>

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

formatProvider
IFormatProvider

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

styles
DateTimeStyles

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

result
DateTimeOffset

메서드가 반환될 때 변환에 성공한 경우 의 input날짜 및 시간에 해당하는 값을 포함하거나 변환에 실패한 경우 DateTimeOffset.MinValue 값을 포함합니다DateTimeOffset. input 매개 변수가 null이거나 날짜 및 시간에 대한 유효한 문자열 표현을 포함하고 있지 않으면 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다.

반환

input 매개 변수가 변환되었으면 true이고, 변환되지 않았으면 false입니다.

적용 대상

TryParse(String, IFormatProvider, DateTimeOffset)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

문자열을 값으로 구문 분석하려고 시도합니다.

public:
 static bool TryParse(System::String ^ s, IFormatProvider ^ provider, [Runtime::InteropServices::Out] DateTimeOffset % result) = IParsable<DateTimeOffset>::TryParse;
public static bool TryParse (string? s, IFormatProvider? provider, out DateTimeOffset result);
static member TryParse : string * IFormatProvider * DateTimeOffset -> bool
Public Shared Function TryParse (s As String, provider As IFormatProvider, ByRef result As DateTimeOffset) As Boolean

매개 변수

s
String

구문 분석할 문자열입니다.

provider
IFormatProvider

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

result
DateTimeOffset

이 메서드가 반환될 때 에는 성공적으로 구문 분석 s 한 결과 또는 실패 시 정의되지 않은 값이 포함됩니다.

반환

true 성공적으로 구문 분석되었으면 s 이고, false그렇지 않으면 입니다.

적용 대상

TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeOffset)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

문자 범위를 값으로 구문 분석하려고 시도합니다.

public:
 static bool TryParse(ReadOnlySpan<char> s, IFormatProvider ^ provider, [Runtime::InteropServices::Out] DateTimeOffset % result) = ISpanParsable<DateTimeOffset>::TryParse;
public static bool TryParse (ReadOnlySpan<char> s, IFormatProvider? provider, out DateTimeOffset result);
static member TryParse : ReadOnlySpan<char> * IFormatProvider * DateTimeOffset -> bool
Public Shared Function TryParse (s As ReadOnlySpan(Of Char), provider As IFormatProvider, ByRef result As DateTimeOffset) As Boolean

매개 변수

s
ReadOnlySpan<Char>

구문 분석할 문자의 범위입니다.

provider
IFormatProvider

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

result
DateTimeOffset

이 메서드가 반환될 때 에는 성공적으로 구문 분석 s한 결과 또는 실패 시 정의되지 않은 값이 포함됩니다.

반환

true 성공적으로 구문 분석되었으면 s 이고, false그렇지 않으면 입니다.

적용 대상

TryParse(ReadOnlySpan<Char>, DateTimeOffset)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

날짜 및 시간의 지정된 범위 표현을 해당 DateTimeOffset 요소로 변환하고, 변환에 성공했는지 여부를 나타내는 값을 반환하려고 시도합니다.

public:
 static bool TryParse(ReadOnlySpan<char> input, [Runtime::InteropServices::Out] DateTimeOffset % result);
public static bool TryParse (ReadOnlySpan<char> input, out DateTimeOffset result);
static member TryParse : ReadOnlySpan<char> * DateTimeOffset -> bool
Public Shared Function TryParse (input As ReadOnlySpan(Of Char), ByRef result As DateTimeOffset) As Boolean

매개 변수

input
ReadOnlySpan<Char>

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

result
DateTimeOffset

메서드가 반환될 때 변환에 성공한 경우 의 input날짜 및 시간에 해당하는 를 포함하거나 변환에 실패한 경우 DateTimeOffset.MinValue를 포함합니다DateTimeOffset. input 매개 변수가 null이거나 날짜 및 시간에 대한 유효한 문자열 표현을 포함하고 있지 않으면 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다.

반환

input 매개 변수가 변환되었으면 true이고, 변환되지 않았으면 false입니다.

적용 대상

TryParse(String, DateTimeOffset)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

날짜와 시간에 대한 지정된 문자열 표현을 해당 DateTimeOffset 요소로 변환하고, 변환에 성공했는지를 나타내는 값을 반환합니다.

public:
 static bool TryParse(System::String ^ input, [Runtime::InteropServices::Out] DateTimeOffset % result);
public static bool TryParse (string input, out DateTimeOffset result);
public static bool TryParse (string? input, out DateTimeOffset result);
static member TryParse : string * DateTimeOffset -> bool
Public Shared Function TryParse (input As String, ByRef result As DateTimeOffset) As Boolean

매개 변수

input
String

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

result
DateTimeOffset

메서드가 반환될 때 변환에 성공한 경우 의 input날짜 및 시간에 해당하는 를 포함하거나 변환에 실패한 경우 DateTimeOffset.MinValue를 포함합니다DateTimeOffset. input 매개 변수가 null이거나 날짜 및 시간에 대한 유효한 문자열 표현을 포함하고 있지 않으면 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다.

반환

input 매개 변수가 변환되었으면 true이고, 변환되지 않았으면 false입니다.

예제

다음 예제에서는 메서드를 TryParse(String, DateTimeOffset) 호출하여 다양한 날짜 및 시간 형식으로 여러 문자열을 구문 분석합니다.

DateTimeOffset parsedDate;
string dateString;

// String with date only
dateString = "05/01/2008";
if (DateTimeOffset.TryParse(dateString, out parsedDate))
   Console.WriteLine("{0} was converted to {1}.",
                     dateString, parsedDate);

// String with time only
dateString = "11:36 PM";
if (DateTimeOffset.TryParse(dateString, out parsedDate))
   Console.WriteLine("{0} was converted to {1}.",
                     dateString, parsedDate);

// String with date and offset
dateString = "05/01/2008 +7:00";
if (DateTimeOffset.TryParse(dateString, out parsedDate))
   Console.WriteLine("{0} was converted to {1}.",
                     dateString, parsedDate);

// String with day abbreviation
dateString = "Thu May 01, 2008";
if (DateTimeOffset.TryParse(dateString, out parsedDate))
   Console.WriteLine("{0} was converted to {1}.",
                     dateString, parsedDate);

// String with date, time with AM/PM designator, and offset
dateString = "5/1/2008 10:00 AM -07:00";
if (DateTimeOffset.TryParse(dateString, out parsedDate))
   Console.WriteLine("{0} was converted to {1}.",
                     dateString, parsedDate);
// if (run on 3/29/07, the example displays the following output
// to the console:
//    05/01/2008 was converted to 5/1/2008 12:00:00 AM -07:00.
//    11:36 PM was converted to 3/29/2007 11:36:00 PM -07:00.
//    05/01/2008 +7:00 was converted to 5/1/2008 12:00:00 AM +07:00.
//    Thu May 01, 2008 was converted to 5/1/2008 12:00:00 AM -07:00.
//    5/1/2008 10:00 AM -07:00 was converted to 5/1/2008 10:00:00 AM -07:00.
// String with date only
let dateString = "05/01/2008"
match DateTimeOffset.TryParse dateString with
| true, parsedDate ->
    printfn $"{dateString} was converted to {parsedDate}."
| _ -> ()

// String with time only
let dateString = "11:36 PM"
match DateTimeOffset.TryParse dateString with
| true, parsedDate ->
    printfn $"{dateString} was converted to {parsedDate}."
| _ -> ()

// String with date and offset
let dateString = "05/01/2008 +7:00"
match DateTimeOffset.TryParse dateString with
| true, parsedDate ->
    printfn $"{dateString} was converted to {parsedDate}."
| _ -> ()

// String with day abbreviation
let dateString = "Thu May 01, 2008"
match DateTimeOffset.TryParse dateString with
| true, parsedDate ->
    printfn $"{dateString} was converted to {parsedDate}."
| _ -> ()

// String with date, time with AM/PM designator, and offset
let dateString = "5/1/2008 10:00 AM -07:00"
match DateTimeOffset.TryParse dateString with
| true, parsedDate ->
    printfn $"{dateString} was converted to {parsedDate}."
| _ -> ()

// if (run on 3/29/07, the example displays the following output
// to the console:
//    05/01/2008 was converted to 5/1/2008 12:00:00 AM -07:00.
//    11:36 PM was converted to 3/29/2007 11:36:00 PM -07:00.
//    05/01/2008 +7:00 was converted to 5/1/2008 12:00:00 AM +07:00.
//    Thu May 01, 2008 was converted to 5/1/2008 12:00:00 AM -07:00.
//    5/1/2008 10:00 AM -07:00 was converted to 5/1/2008 10:00:00 AM -07:00.
Dim parsedDate As DateTimeOffset
Dim dateString As String

' String with date only
dateString = "05/01/2008"
If DateTimeOffset.TryParse(dateString, parsedDate) Then _
   Console.WriteLine("{0} was converted to {1}.", _
                     dateString, parsedDate)

' String with time only
dateString = "11:36 PM"
If DateTimeOffset.TryParse(dateString, parsedDate) Then _
   Console.WriteLine("{0} was converted to {1}.", _
                     dateString, parsedDate)

' String with date and offset 
dateString = "05/01/2008 +7:00"
If DateTimeOffset.TryParse(dateString, parsedDate) Then _
   Console.WriteLine("{0} was converted to {1}.", _
                     dateString, parsedDate)

' String with day abbreviation
dateString = "Thu May 01, 2008"
If DateTimeOffset.TryParse(dateString, parsedDate) Then _
   Console.WriteLine("{0} was converted to {1}.", _
                     dateString, parsedDate)

' String with date, time with AM/PM designator, and offset
dateString = "5/1/2008 10:00 AM -07:00"
If DateTimeOffset.TryParse(dateString, parsedDate) Then _
   Console.WriteLine("{0} was converted to {1}.", _
                     dateString, parsedDate)
' If run on 3/29/07, the example displays the following output
' to the console:
'    05/01/2008 was converted to 5/1/2008 12:00:00 AM -07:00.
'    11:36 PM was converted to 3/29/2007 11:36:00 PM -07:00.
'    05/01/2008 +7:00 was converted to 5/1/2008 12:00:00 AM +07:00.
'    Thu May 01, 2008 was converted to 5/1/2008 12:00:00 AM -07:00.
'    5/1/2008 10:00 AM -07:00 was converted to 5/1/2008 10:00:00 AM -07:00.

설명

메서드의 TryParse(String, DateTimeOffset) 이 오버로드는 변환이 DateTimeOffset.Parse(String) 실패할 경우 예외를 throw하지 않는다는 점을 제외하고 메서드와 같습니다. 임의의 순서로 표시될 수 있고 공백으로 구분되는 세 가지 요소가 있는 문자열을 구문 분석합니다. 이러한 세 가지 요소는 다음 표에 나와 있습니다.

요소 예제
<Date> "2/10/2007"
<Time> "오후 1:02:03"
<Offset> "-7:30"

이러한 각 요소는 선택 사항이지만 Offset <> 은 단독으로 표시할 수 없습니다. 날짜> 또는 <시간과> 함께 <제공되어야 합니다. Date>가 누락된 경우 <기본값은 현재 날짜입니다. Date>가 있지만 해당 연도 구성 요소가 두 자리 숫자로만 구성된 경우 <속성 값 Calendar.TwoDigitYearMax 에 따라 현재 문화권의 현재 달력에서 1년으로 변환됩니다. Time>이 누락된 경우 <기본값은 오전 12:00:00입니다. Offset>이 누락된 경우 <기본값은 현지 표준 시간대의 오프셋입니다. Offset>이 있는 경우 <UTC(협정 세계시)의 음수 또는 양수 오프셋을 나타낼 수 있습니다. 두 경우 모두 Offset>은 <기호 기호를 포함해야 합니다. 그렇지 않으면 메서드가 를 반환합니다false.

문자열은 input 현재 문화권에 대해 초기화된 개체의 DateTimeFormatInfo 서식 정보를 사용하여 구문 분석됩니다. 현재 문화권과 반드시 일치하지 않는 지정된 서식이 포함된 문자열을 구문 분석하려면 메서드를 TryParseExact 사용하고 형식 지정자를 제공합니다.

추가 정보

적용 대상