XmlConvert.ToDateTimeOffset 메서드

정의

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

오버로드

Name 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[]

변환할 수 있는 s 형식 배열입니다. 각 형식은 formats XML dateTime 형식에 대한 W3C 권장 사항의 하위 집합일 수 있습니다. (자세한 내용은 XML 스키마 사양의 dateTime 섹션을 참조하세요.) 문자열 s 은 이러한 형식 중 하나에 대해 유효성을 검사합니다.

반품

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

예제

다음 예제에서는 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의 역직렬화된 표현에서 오버플로가 발생하는 경우 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

변환되는 s 형식입니다. 형식 매개 변수는 XML dateTime 형식에 대한 W3C 권장 사항의 하위 집합일 수 있습니다. (자세한 내용은 XML 스키마 사양의 dateTime 섹션을 참조하세요.) 이 형식에 대해 문자열 s 의 유효성이 검사됩니다.

반품

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

예외

snull입니다.

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의 역직렬화된 표현에서 오버플로가 발생하는 경우 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 됩니다.

적용 대상