XmlConvert.ToDateTime 메서드

정의

String을 해당하는 DateTime 값으로 변환합니다.

오버로드

ToDateTime(String)
사용되지 않습니다.
사용되지 않습니다.

String을 해당하는 DateTime 값으로 변환합니다.

ToDateTime(String, String)

String을 해당하는 DateTime 값으로 변환합니다.

ToDateTime(String, String[])

String을 해당하는 DateTime 값으로 변환합니다.

ToDateTime(String, XmlDateTimeSerializationMode)

지정된 String를 사용하여 DateTimeXmlDateTimeSerializationMode으로 변환합니다.

ToDateTime(String)

주의

Use XmlConvert.ToDateTime() that takes in XmlDateTimeSerializationMode

주의

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

String을 해당하는 DateTime 값으로 변환합니다.

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

매개 변수

s
String

변환할 문자열입니다.

반환

DateTime

문자열에 해당하는 DateTime 값입니다.

특성

예외

s이(가) null인 경우

s가 빈 문자열이거나 형식이 잘못된 경우

예제

다음 예제에서는 강력한 형식의 데이터를 사용하고 ToDouble ToDateTime 읽습니다.

#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

이 예제에서는 파일을 orderData.xml입력으로 사용합니다.

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

설명

참고

XmlConvert.ToDateTime(String) 메서드는 .NET Framework 2.0 버전에서 사용되지 않으며 메서드로 XmlConvert.ToDateTime(String, XmlDateTimeSerializationMode) 대체되었습니다.

적용 대상

ToDateTime(String, String)

String을 해당하는 DateTime 값으로 변환합니다.

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

매개 변수

s
String

변환할 문자열입니다.

format
String

변환된 DateTime에 적용할 형식 구조입니다. 올바른 형식에는 "yyyy-MM-ddTHH:mm:sszzzzzz" 및 그 하위 집합이 포함됩니다. 문자열은 이 형식에 대해 유효성을 확인합니다.

반환

DateTime

문자열에 해당하는 DateTime 값입니다.

예외

s이(가) null인 경우

s 또는 format이 String.Empty인 경우 또는 sformat과 일치하는 날짜와 시간이 포함되지 않는 경우

적용 대상

ToDateTime(String, String[])

String을 해당하는 DateTime 값으로 변환합니다.

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

매개 변수

s
String

변환할 문자열입니다.

formats
String[]

변환된 DateTime에 적용할 형식 구조가 포함된 배열입니다. 올바른 형식에는 "yyyy-MM-ddTHH:mm:sszzzzzz" 및 그 하위 집합이 포함됩니다.

반환

DateTime

문자열에 해당하는 DateTime 값입니다.

예외

s이(가) null인 경우

s 또는 formats의 요소가 String.Empty인 경우 또는 sformats의 요소에 해당하는 날짜와 시간이 포함되지 않은 경우

설명

이 메서드를 사용하면 문자열에 대한 여러 형식의 유효성을 검사할 수 있습니다.

적용 대상

ToDateTime(String, XmlDateTimeSerializationMode)

지정된 String를 사용하여 DateTimeXmlDateTimeSerializationMode으로 변환합니다.

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

매개 변수

s
String

변환할 String 값입니다.

dateTimeOption
XmlDateTimeSerializationMode

UTC(Coordinated Universal Time) 날짜를 현지 시간으로 변환할지 아니면 UTC로 유지할지 지정하는 열거형 값 중 하나입니다.

반환

DateTime

DateTime에 해당하는 String 값입니다.

예외

s이(가) null인 경우

dateTimeOption이(가) null인 경우

s가 빈 문자열이거나 형식이 잘못된 경우

적용 대상