Aracılığıyla paylaş


XmlConvert.ToDateTimeOffset Yöntem

Tanım

Sağlanan String öğesini eşdeğerine DateTimeOffset dönüştürür.

Aşırı Yüklemeler

ToDateTimeOffset(String, String[])

Sağlanan String öğesini eşdeğerine DateTimeOffset dönüştürür.

ToDateTimeOffset(String, String)

Sağlanan String öğesini eşdeğerine DateTimeOffset dönüştürür.

ToDateTimeOffset(String)

Sağlanan String öğesini eşdeğerine DateTimeOffset dönüştürür.

ToDateTimeOffset(String, String[])

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

Sağlanan String öğesini eşdeğerine DateTimeOffset dönüştürür.

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

Parametreler

s
String

Dönüştürülecek dize.

formats
String[]

Dönüştürülebilecek s biçim dizisi. içindeki formats her biçim, XML dateTime türü için W3C Önerisi'nin herhangi bir alt kümesi olabilir. (Daha fazla bilgi için XML Şeması belirtiminin dateTime bölümüne bakın..) Dize s bu biçimlerden birine göre doğrulanır.

Döndürülenler

Sağlanan DateTimeOffset dizenin eşdeğeri.

Örnekler

Aşağıdaki örnekte, XML dosyasından bir dizenin nasıl okunduğu ve dizeyi bir DateTimeOffset türe dönüştürmek için yönteminin ToDateTimeOffset nasıl kullanılacağı gösterilmektedir. Giriş dizesinin dönüştürülmeden önce belirtilen biçimlerden birine göre doğrulanması gerekir.

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

Örnekte transactions.xml dosyası kullanılır.

<?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>

Açıklamalar

Giriş dizesi içinde belirtilen uzaklık DateTimeOffset'in seri durumdan çıkarılmış gösteriminde taşmalara neden olacaksa, bir FormatException oluşturulur.

Kesirli saniyeler için yediden fazla basamak belirtildiğinde, değer yuvarlanir. Örneğin, 00000004 0000000 olur ve 00000005 0000001 olur.

Şunlara uygulanır

ToDateTimeOffset(String, String)

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

Sağlanan String öğesini eşdeğerine DateTimeOffset dönüştürür.

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

Parametreler

s
String

Dönüştürülecek dize.

format
String

Dönüştürülen s biçim. format parametresi, XML dateTime türü için W3C Önerisi'nin herhangi bir alt kümesi olabilir. (Daha fazla bilgi için XML Şeması belirtiminin dateTime bölümüne bakın..) Dize s bu biçime göre doğrulanır.

Döndürülenler

Sağlanan DateTimeOffset dizenin eşdeğeri.

Özel durumlar

s, null değeridir.

s veya format boş bir dizedir veya belirtilen biçimde değildir.

Örnekler

Aşağıdaki örnekte, XML dosyasından bir dizenin nasıl okunduğu ve dizeyi bir DateTimeOffset türe dönüştürmek için yönteminin ToDateTimeOffset nasıl kullanılacağı gösterilmektedir. Giriş dizesi, dönüştürülmeden önce belirtilen biçime göre doğrulanır.

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

Örnekte transactions.xml dosyası kullanılır.

<?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>

Açıklamalar

Giriş dizesi içinde belirtilen uzaklık DateTimeOffset'in seri durumdan çıkarılmış gösteriminde taşmalara neden olacaksa, bir FormatException oluşturulur.

Kesirli saniyeler için yediden fazla basamak belirtildiğinde, değer yuvarlanir. Örneğin, 00000004 0000000 olur ve 00000005 0000001 olur.

Şunlara uygulanır

ToDateTimeOffset(String)

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

Sağlanan String öğesini eşdeğerine DateTimeOffset dönüştürür.

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

Parametreler

s
String

Dönüştürülecek dize. Dize, XML dateTime türü için W3C Önerisi'nin bir alt kümesine uygun olmalıdır. Daha fazla bilgi için XML Şeması belirtiminin dateTime bölümüne bakın.

Döndürülenler

Sağlanan DateTimeOffset dizenin eşdeğeri.

Özel durumlar

s, null değeridir.

Bu yönteme geçirilen bağımsız değişken, izin verilebilen değer aralığının dışındadır. İzin verilebilen değerler hakkında bilgi için bkz DateTimeOffset. .

Bu yönteme geçirilen bağımsız değişken, XML dateTime türü için W3C Önerileri'nin bir alt kümesine uymuyor. Daha fazla bilgi için XML Şeması belirtiminin dateTime bölümüne bakın.

Örnekler

Aşağıdaki örnekte, XML dosyasından bir dizenin nasıl okunduğu ve dizeyi bir DateTimeOffset türe dönüştürmek için yönteminin ToDateTimeOffset nasıl kullanılacağı gösterilmektedir.

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

Örnekte transactions.xml dosyası kullanılır.

<?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>

Açıklamalar

Kesirli saniyeler için yediden fazla basamak belirtildiğinde, değer yuvarlanir. Örneğin, 00000004 0000000 olur ve 00000005 0000001 olur.

Şunlara uygulanır