XmlConvert.ToDateTime Metoda

Definicja

Konwertuje element String na DateTime odpowiednik.

Przeciążenia

ToDateTime(String)
Przestarzałe.
Przestarzałe.

Konwertuje element String na DateTime odpowiednik.

ToDateTime(String, String)

Konwertuje element String na DateTime odpowiednik.

ToDateTime(String, String[])

Konwertuje element String na DateTime odpowiednik.

ToDateTime(String, XmlDateTimeSerializationMode)

Konwertuje element String na DateTime przy użyciu określonego XmlDateTimeSerializationMode .

ToDateTime(String)

Źródło:
XmlConvert.cs
Źródło:
XmlConvert.cs
Źródło:
XmlConvert.cs

Przestroga

Use XmlConvert.ToDateTime() that takes in XmlDateTimeSerializationMode

Przestroga

Use XmlConvert.ToDateTime() that accepts an XmlDateTimeSerializationMode instead.

Konwertuje element String na DateTime odpowiednik.

public:
 static DateTime ToDateTime(System::String ^ s);
[System.Obsolete("Use XmlConvert.ToDateTime() that takes in XmlDateTimeSerializationMode")]
public static DateTime ToDateTime (string s);
[System.Obsolete("Use XmlConvert.ToDateTime() that accepts an XmlDateTimeSerializationMode instead.")]
public static DateTime ToDateTime (string s);
public static DateTime ToDateTime (string s);
[<System.Obsolete("Use XmlConvert.ToDateTime() that takes in XmlDateTimeSerializationMode")>]
static member ToDateTime : string -> DateTime
[<System.Obsolete("Use XmlConvert.ToDateTime() that accepts an XmlDateTimeSerializationMode instead.")>]
static member ToDateTime : string -> DateTime
static member ToDateTime : string -> DateTime
Public Shared Function ToDateTime (s As String) As DateTime

Parametry

s
String

Ciąg do konwersji.

Zwraca

Odpowiednik DateTime ciągu.

Atrybuty

Wyjątki

s jest pustym ciągiem lub nie jest w poprawnym formacie.

Przykłady

W poniższym przykładzie użyto ToDouble metody i ToDateTime odczytano silnie typizowane dane.

#using <System.dll>
#using <System.xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ reader = gcnew XmlTextReader( "orderData.xml" );
   
   //Parse the file and pull out the order date and price.
   while ( reader->Read() )
   {
      if ( reader->NodeType == XmlNodeType::Element )
      {
         if ( reader->Name->Equals( "order" ) )
         {
            DateTime orderDate = XmlConvert::ToDateTime( reader->GetAttribute( "date" ) );
            Console::WriteLine( "order date: {0}", orderDate.ToString() );
         }
         else
         if ( reader->Name->Equals( "price" ) )
         {
            Double price = XmlConvert::ToDouble( reader->ReadInnerXml() );
            Console::WriteLine( "price: {0}", price );
         }
      }
   }

   
   //Close the reader.
   reader->Close();
}
using System;
using System.IO;
using System.Xml;

public class Sample
{

  public static void Main()
  {
    XmlTextReader reader = new XmlTextReader("orderData.xml");

    //Parse the file and pull out the order date and price.
    while (reader.Read()){
       if (reader.NodeType==XmlNodeType.Element){
         switch(reader.Name){
           case "order":
             DateTime orderDate = XmlConvert.ToDateTime(reader.GetAttribute("date"));
             Console.WriteLine("order date: {0}", orderDate.ToString());
             break;
           case "price":
             Double price = XmlConvert.ToDouble(reader.ReadInnerXml());
             Console.WriteLine("price: {0}", price.ToString());
             break;
         }
       }
    }

    //Close the reader.
    reader.Close();
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()
  
    Dim reader as XmlTextReader = new XmlTextReader("orderData.xml")

    'Parse the file and pull out the order date and price.
    while (reader.Read())
       if (reader.NodeType=XmlNodeType.Element)
         select case reader.Name
           case "order":
             Dim orderDate as DateTime = XmlConvert.ToDateTime(reader.GetAttribute("date"))
             Console.WriteLine("order date: {0}", orderDate.ToString())
           case "price":
             Dim price as Double = XmlConvert.ToDouble(reader.ReadInnerXml())
             Console.WriteLine("price: {0}", price.ToString())
         end select
       end if
    end while

    'Close the reader.
    reader.Close()  
  end sub
end class

W przykładzie użyto pliku , orderData.xmljako danych wejściowych.

<order date="2001-05-03">
  <orderID>367A54</orderID>
  <custID>32632</custID>
  <price>19.95</price>
</order>

Uwagi

Uwaga

Metoda XmlConvert.ToDateTime(String) jest przestarzała w wersji 2.0 .NET Framework i została zastąpiona przez metodę XmlConvert.ToDateTime(String, XmlDateTimeSerializationMode) .

Dotyczy

ToDateTime(String, String)

Źródło:
XmlConvert.cs
Źródło:
XmlConvert.cs
Źródło:
XmlConvert.cs

Konwertuje element String na DateTime odpowiednik.

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

Parametry

s
String

Ciąg do konwersji.

format
String

Struktura formatu, która ma być stosowana do przekonwertowanego DateTimeobiektu . Prawidłowe formaty obejmują "rrrr-MM-ddTHH:mm:sszzzzzz" i jego podzestawy. Ciąg jest weryfikowany w tym formacie.

Zwraca

Odpowiednik DateTime ciągu.

Wyjątki

s lub format jest Ciąg.Empty

-lub-

snie zawiera daty i godziny odpowiadającej .format

Dotyczy

ToDateTime(String, String[])

Źródło:
XmlConvert.cs
Źródło:
XmlConvert.cs
Źródło:
XmlConvert.cs

Konwertuje element String na DateTime odpowiednik.

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

Parametry

s
String

Ciąg do konwersji.

formats
String[]

Tablica zawierająca struktury formatu, które mają być stosowane do przekonwertowanego DateTimeobiektu . Prawidłowe formaty obejmują "rrrr-MM-ddTHH:mm:sszzzzzz" i jego podzestawy.

Zwraca

Odpowiednik DateTime ciągu.

Wyjątki

s lub element elementu formats to String.Empty

-lub-

s nie zawiera daty i godziny odpowiadającej żadnym elementom elementu formats.

Uwagi

Ta metoda umożliwia zweryfikowanie wielu formatów ciągu.

Dotyczy

ToDateTime(String, XmlDateTimeSerializationMode)

Źródło:
XmlConvert.cs
Źródło:
XmlConvert.cs
Źródło:
XmlConvert.cs

Konwertuje element String na DateTime przy użyciu określonego XmlDateTimeSerializationMode .

public:
 static DateTime ToDateTime(System::String ^ s, System::Xml::XmlDateTimeSerializationMode dateTimeOption);
public static DateTime ToDateTime (string s, System.Xml.XmlDateTimeSerializationMode dateTimeOption);
static member ToDateTime : string * System.Xml.XmlDateTimeSerializationMode -> DateTime
Public Shared Function ToDateTime (s As String, dateTimeOption As XmlDateTimeSerializationMode) As DateTime

Parametry

s
String

Wartość String do przekonwertowania.

dateTimeOption
XmlDateTimeSerializationMode

Jedna z wartości wyliczenia określająca, czy data powinna zostać przekonwertowana na czas lokalny, czy zachowana jako uniwersalny czas koordynowany (UTC), jeśli jest to data UTC.

Zwraca

Odpowiednik DateTime elementu String.

Wyjątki

dateTimeOption to null.

s jest pustym ciągiem lub nie jest w prawidłowym formacie.

Dotyczy