언어

XmlConvert.ToDateTimeOffset 메서드

정의

제공된 String 값을 해당하는 값으로 DateTimeOffset 변환합니다.

오버로드

속성 Description
ToDateTimeOffset(String, String[])

제공된 String 값을 해당하는 값으로 DateTimeOffset 변환합니다.

ToDateTimeOffset(String, String)

제공된 String 값을 해당하는 값으로 DateTimeOffset 변환합니다.

ToDateTimeOffset(String)

제공된 String 값을 해당하는 값으로 DateTimeOffset 변환합니다.

ToDateTimeOffset(String, String[])

Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs

제공된 String 값을 해당하는 값으로 DateTimeOffset 변환합니다.

public:
 static DateTimeOffset ToDateTimeOffset(System::String ^ s, cli::array <System::String ^> ^ formats);
public static DateTimeOffset ToDateTimeOffset(string s, string[] formats);
static member ToDateTimeOffset : string * string[] -> DateTimeOffset
Public Shared Function ToDateTimeOffset (s As String, formats As String()) As DateTimeOffset

매개 변수

s
String

변환할 문자열입니다.

formats
String[]

허용되는 형식을 지정하는 .NET 표준 또는 사용자 지정 날짜 및 시간 형식 문자열의 s배열입니다.

반품

DateTimeOffset 제공된 문자열에 해당하는 값입니다.

예외

요소가 formats 유효하지 않거나 선행 또는 s 후행 공백을 제외하고 고정 문화권 규칙의 요소 formats 와 정확히 일치하지 않습니다.

예제

다음 예제에서는 XML 파일에서 문자열을 읽고 메서드를 ToDateTimeOffset 사용하여 문자열을 형식으로 변환하는 DateTimeOffset 방법을 보여 줍니다. 입력 문자열은 변환되기 전에 지정된 형식 중 하나에 대해 유효성을 검사해야 합니다.

using System;
using System.Xml;

class Example
{
    static void Main()
    {
        // Create an XmlReader, read to the "time" element, and read contents as type string
        XmlReader reader = XmlReader.Create("transactions.xml");
        reader.ReadToFollowing("time");
        string time = reader.ReadElementContentAsString();

        // Specify formats against which time will be validated before conversion to DateTimeOffset
        // If time does not match one of the specified formats, a FormatException will be thrown.
        // Each specified format must be a subset of the W3C Recommendation for the XML dateTime type
        string[] formats = {"yyyy-MM-ddTHH:mm:sszzzzzzz", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-dd"};
        try
        {
            // Read the element contents as a string and covert to DateTimeOffset type
            DateTimeOffset transaction_time = XmlConvert.ToDateTimeOffset(time, formats);
            Console.WriteLine(transaction_time);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
}
Imports System.Xml

Module Module1
    Sub Main()
        ' Create an XmlReader, read to the "time" element, and read contents as type string
        Dim reader As XmlReader = XmlReader.Create("transactions.xml")
        reader.ReadToFollowing("time")
        Dim time As String = reader.ReadElementContentAsString()

        ' Specify formats against which time will be validated before conversion to DateTimeOffset
        ' If time does not match one of the specified formats, a FormatException will be thrown.
        ' Each specified format must be a subset of the W3C Recommendation for the XML dateTime type
        Dim formats As String() = {"yyyy-MM-ddTHH:mm:sszzzzzzz", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-dd"}
        Try
            ' Read the element contents as a string and covert to DateTimeOffset type
            Dim transaction_time As DateTimeOffset = XmlConvert.ToDateTimeOffset(time, formats)
            Console.WriteLine(transaction_time)
        Catch e As Exception
            Console.WriteLine(e)
        End Try
    End Sub
End Module

이 예제에서는 transactions.xml 파일을 사용합니다.

<?xml version="1.0"?>
<transactions>
   <transaction>
      <id>123456789</id>
      <amount>1.00</amount>
      <currency>USD</currency>
      <time>2007-08-03T22:05:13-07:00</time>
   </transaction>
</transactions>

설명

이 오버로드는 호출 DateTimeOffset.ParseExact(String, String[], IFormatProvider, DateTimeStyles)DateTimeFormatInfo.InvariantInfoAllowLeadingWhite 플래그와 AllowTrailingWhite 동일합니다. 선행 및 후행 공백은 무시되지만 s , 그렇지 않으면 에 있는 formats문자열 중 하나와 정확히 일치해야 합니다. 이 매개 변수는 formats XML 스키마 dateTime 패턴이 아닌 .NET 표준날짜 및 시간 형식 문자열 또는 사용자 지정 날짜 및 시간 형식 문자열을 사용합니다.

사용자 지정 형식 문자열 z에서 , zzzzz 지정자에는 부호 있는 숫자 UTC 오프셋이 필요합니다. XML UTC 지정자와 Z일치하지 않습니다. 포함Z할 수 있는 K 경우 s 사용자 지정 형식 지정자를 사용합니다.

입력 문자열 내에 지정된 오프셋으로 인해 DateTimeOffset의 역직렬화된 표현에서 오버플로가 발생하는 경우 FormatException이 throw됩니다.

소수 자릿수 초 동안 7자리 이상의 숫자를 지정하면 값이 반올림됩니다. 예를 들어 00000004 0000000이 되고 00000005 0000001 됩니다.

적용 대상

ToDateTimeOffset(String, String)

Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs

제공된 String 값을 해당하는 값으로 DateTimeOffset 변환합니다.

public:
 static DateTimeOffset ToDateTimeOffset(System::String ^ s, System::String ^ format);
public static DateTimeOffset ToDateTimeOffset(string s, string format);
static member ToDateTimeOffset : string * string -> DateTimeOffset
Public Shared Function ToDateTimeOffset (s As String, format As String) As DateTimeOffset

매개 변수

s
String

변환할 문자열입니다.

format
String

필요한 형식을 지정하는 .NET 표준 또는 사용자 지정 날짜 및 시간 형식 문자열입니다s.

반품

DateTimeOffset 제공된 문자열에 해당하는 값입니다.

예외

snull입니다.

format 가 잘못되었거나 선행 또는 s 후행 공백을 제외하고 고정 문화권 규칙에 따라 정확히 일치하지 format 않습니다.

예제

다음 예제에서는 XML 파일에서 문자열을 읽고 메서드를 ToDateTimeOffset 사용하여 문자열을 형식으로 변환하는 DateTimeOffset 방법을 보여 줍니다. 입력 문자열은 변환되기 전에 지정된 형식에 대해 유효성을 검사합니다.

using System;
using System.Xml;

class Example
{
    static void Main()
    {
        // Create an XmlReader, read to the "time" element, and read contents as type string
        XmlReader reader = XmlReader.Create("transactions.xml");
        reader.ReadToFollowing("time");
        string time = reader.ReadElementContentAsString();

        // Specify a format against which time will be validated before conversion to DateTimeOffset
        // If time does not match the format, a FormatException will be thrown.
        // The specified format must be a subset of the W3C Recommendation for the XML dateTime type
        string format = "yyyy-MM-ddTHH:mm:sszzzzzzz";
        try
        {
            // Read the element contents as a string and covert to DateTimeOffset type
            DateTimeOffset transaction_time = XmlConvert.ToDateTimeOffset(time, format);
            Console.WriteLine(transaction_time);
        }
        catch(Exception e)
        {
            Console.WriteLine(e);
        }
    }
}
Imports System.Xml

Module Module1      
    Sub Main()
        ' Create an XmlReader, read to the "time" element, and read contents as type string
        Dim reader As XmlReader = XmlReader.Create("transactions.xml")
        reader.ReadToFollowing("time")
        Dim time As String = reader.ReadElementContentAsString()

        ' Specify a format against which time will be validated before conversion to DateTimeOffset
        ' If time does not match the format, a FormatException will be thrown.
        ' The specified format must be a subset of the W3C Recommendation for the XML dateTime type
        Dim format As String = "yyyy-MM-ddTHH:mm:sszzzzzzz"
        Try
            ' Read the element contents as a string and covert to DateTimeOffset type
            Dim transaction_time As DateTimeOffset = XmlConvert.ToDateTimeOffset(time, format)
            Console.WriteLine(transaction_time)
        Catch e As Exception
            Console.WriteLine(e)
        End Try
    End Sub
End Module

이 예제에서는 transactions.xml 파일을 사용합니다.

<?xml version="1.0"?>
<transactions>
   <transaction>
      <id>123456789</id>
      <amount>1.00</amount>
      <currency>USD</currency>
      <time>2007-08-03T22:05:13-07:00</time>
   </transaction>
</transactions>

설명

이 오버로드는 호출 DateTimeOffset.ParseExact(String, String, IFormatProvider, DateTimeStyles)DateTimeFormatInfo.InvariantInfoAllowLeadingWhite 플래그와 AllowTrailingWhite 동일합니다. 선행 및 후행 공백은 무시되지만 s , 그렇지 않으면 정확히 일치 format해야 합니다. 이 매개 변수는 format XML 스키마 dateTime 패턴이 아닌 .NET 표준날짜 및 시간 형식 문자열 또는 사용자 지정 날짜 및 시간 형식 문자열을 사용합니다.

사용자 지정 형식 문자열 z에서 , zzzzz 지정자에는 부호 있는 숫자 UTC 오프셋이 필요합니다. XML UTC 지정자와 Z일치하지 않습니다. 포함Z할 수 있는 K 경우 s 사용자 지정 형식 지정자를 사용합니다.

입력 문자열 내에 지정된 오프셋으로 인해 DateTimeOffset의 역직렬화된 표현에서 오버플로가 발생하는 경우 FormatException이 throw됩니다.

소수 자릿수 초 동안 7자리 이상의 숫자를 지정하면 값이 반올림됩니다. 예를 들어 00000004 0000000이 되고 00000005 0000001 됩니다.

적용 대상

ToDateTimeOffset(String)

Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs
Source:
XmlConvert.cs

제공된 String 값을 해당하는 값으로 DateTimeOffset 변환합니다.

public:
 static DateTimeOffset ToDateTimeOffset(System::String ^ s);
public static DateTimeOffset ToDateTimeOffset(string s);
static member ToDateTimeOffset : string -> DateTimeOffset
Public Shared Function ToDateTimeOffset (s As String) As DateTimeOffset

매개 변수

s
String

변환할 문자열입니다. 문자열은 XML dateTime 형식에 대한 W3C 권장 사항의 하위 집합을 준수해야 합니다. 자세한 내용은 XML 스키마 사양의 dateTime 섹션을 참조하세요.

반품

DateTimeOffset 제공된 문자열에 해당하는 값입니다.

예외

snull입니다.

이 메서드에 전달된 인수가 허용 가능한 값 범위를 벗어났습니다. 허용되는 값에 대한 자세한 내용은 다음을 참조하세요 DateTimeOffset.

이 메서드에 전달된 인수는 XML dateTime 형식에 대한 W3C 권장 사항의 하위 집합을 따르지 않습니다. 자세한 내용은 XML 스키마 사양의 dateTime 섹션을 참조하세요.

예제

다음 예제에서는 XML 파일에서 문자열을 읽고 메서드를 ToDateTimeOffset 사용하여 문자열을 형식으로 변환하는 DateTimeOffset 방법을 보여 줍니다.

using System;
using System.Xml;

class Example
{
    static void Main()
    {
        // Create an XmlReader, read to the "time" element, and read contents as type string
        XmlReader reader = XmlReader.Create("transactions.xml");
        reader.ReadToFollowing("time");
        string time = reader.ReadElementContentAsString();

        // Read the element contents as a string and covert to DateTimeOffset type
        // The format of time must be a subset of the W3C Recommendation for the XML dateTime type
        DateTimeOffset transaction_time = XmlConvert.ToDateTimeOffset(time);
        Console.WriteLine(transaction_time);
    }
}
Imports System.Xml

Module Module1
    Sub Main()
        ' Create an XmlReader, read to the "time" element, and read contents as type string
        Dim reader As XmlReader = XmlReader.Create("transactions.xml")
        reader.ReadToFollowing("time")
        Dim time As String = reader.ReadElementContentAsString()

        ' Read the element contents as a string and covert to DateTimeOffset type
    ' The format of time must be a subset of the W3C Recommendation for the XML dateTime type
        Dim transaction_time As DateTimeOffset = XmlConvert.ToDateTimeOffset(time)
        Console.WriteLine(transaction_time)
    End Sub
End Module

이 예제에서는 transactions.xml 파일을 사용합니다.

<?xml version="1.0"?>
<transactions>
   <transaction>
      <id>123456789</id>
      <amount>1.00</amount>
      <currency>USD</currency>
      <time>2007-08-03T22:05:13-07:00</time>
   </transaction>
</transactions>

설명

소수 자릿수 초 동안 7자리 이상의 숫자를 지정하면 값이 반올림됩니다. 예를 들어 00000004 0000000이 되고 00000005 0000001 됩니다.

적용 대상