SoapDuration.Parse(String) 方法

定义

将指定的 String 转换为 TimeSpan 对象。

public:
 static TimeSpan Parse(System::String ^ value);
public static TimeSpan Parse (string value);
static member Parse : string -> TimeSpan
Public Shared Function Parse (value As String) As TimeSpan

参数

value
String

要转换的 String

返回

value 获取的 TimeSpan 对象。

例外

value 不包含与任何识别的格式模式相对应的日期和时间。

示例

下面的代码示例说明如何使用 Parse 方法。 此代码示例是为 SoapDuration 类提供的一个更大示例的一部分。

// Parse an XSD duration to create a TimeSpan object.
// This is a duration of 2 years, 3 months, 9 days, 12 hours,
// 35 minutes, 20 seconds, and 10 milliseconds.
String^ xsdDuration = L"P2Y3M9DT12H35M20.0100000S";
TimeSpan timeSpan = SoapDuration::Parse( xsdDuration );
Console::WriteLine( L"The time span contains {0} days.",
   timeSpan.Days );
Console::WriteLine( L"The time span contains {0} hours.",
   timeSpan.Hours );
Console::WriteLine( L"The time span contains {0} minutes.",
   timeSpan.Minutes );
Console::WriteLine( L"The time span contains {0} seconds.",
   timeSpan.Seconds );
// Parse an XSD duration to create a TimeSpan object.
// This is a duration of 2 years, 3 months, 9 days, 12 hours,
// 35 minutes, 20 seconds, and 10 milliseconds.
string xsdDuration = "P2Y3M9DT12H35M20.0100000S";
TimeSpan timeSpan = SoapDuration.Parse(xsdDuration);
Console.WriteLine("The time span contains {0} days.",
    timeSpan.Days);
Console.WriteLine("The time span contains {0} hours.",
    timeSpan.Hours);
Console.WriteLine("The time span contains {0} minutes.",
    timeSpan.Minutes);
Console.WriteLine("The time span contains {0} seconds.",
    timeSpan.Seconds);

适用于