本文整理匯總了C#中System.Xml.XmlConvert.ToDateTimeOffset方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlConvert.ToDateTimeOffset方法的具體用法?C# XmlConvert.ToDateTimeOffset怎麽用?C# XmlConvert.ToDateTimeOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了XmlConvert.ToDateTimeOffset方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
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);
}
}
}
示例2: Main
//引入命名空間
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);
}
}
}
示例3: Main
//引入命名空間
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);
}
}