SoapDuration.Parse(String) Method

Definition

Converts the specified String into a TimeSpan object.

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

Parameters

value
String

The String to convert.

Returns

A TimeSpan object that is obtained from value.

Exceptions

value does not contain a date and time that corresponds to any of the recognized format patterns.

Examples

The following code example shows how to use the Parse method. This code example is part of a larger example that is provided for the SoapDuration class.

// 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);

Applies to