本文整理汇总了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);
}
}