System.Xml.XmlConvert.ToString 方法 (DateTimeOffset, String)
方法描述
将提供的 DateTimeOffset 转换为指定格式的 String。
语法定义(C# System.Xml.XmlConvert.ToString 方法 (DateTimeOffset, String) 的用法)
public static string ToString( DateTimeOffset value, string format )
参数/返回值
| 参数值/返回值 | 参数类型/返回类型 | 参数描述/返回描述 |
|---|---|---|
| value | System-DateTimeOffset | 要转换的 DateTimeOffset。 |
| format | System-String | s 转换为的格式。该格式参数可以是 XML DateTime 类型的 W3C 建议的任何子集。(有关更多信息,请参见 http://www.w3.org/TR/xmlschema-2/。) |
| 返回值 | System.String | 所提供 DateTimeOffset 的指定格式的 String 表示形式。 |
提示和注释
System.Xml.XmlConvert.ToString 方法 (DateTimeOffset, String)例子
下面的示例将当前时间的 DateTimeOffset 表示形式转换为指定格式的 String。
using System;
using System.Xml;
class Example
{
static void Main()
{
// Create the DateTimeOffset object and set the time to the current time.
DateTimeOffset dto;
dto = DateTimeOffset.Now;
// Convert the DateTimeObject to a string in a specified format and display the result.
// The specified format must be a subset of the W3C Recommendation for the XML dateTime type.
String timeAsString = XmlConvert.ToString(dto, "yyyy-MM-ddTHH:mm:sszzzzzzz");
Console.WriteLine(timeAsString);
}
}
版本信息
.NET Framework 受以下版本支持:4、3.5 SP1、3.0 SP1、2.0 SP1 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1 受以下版本支持:
适用平台
Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。