Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

TimeSpan.TryParse Method

Note: This method is new in the .NET Framework version 2.0.

Constructs a new TimeSpan object from a time interval specified in a string. Parameters specify the time interval and the variable where the new TimeSpan object is returned.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static bool TryParse (
	string s,
	out TimeSpan result
)
public static boolean TryParse (
	String s, 
	/** @attribute OutAttribute() */ /** @ref */ TimeSpan result
)
JScript does not support passing value-type arguments by reference.

Parameters

s

A string that specifies a time interval.

result

When this method returns, contains an object that represents the time interval specified by s, or Zero if the conversion failed. This parameter is passed uninitialized.

Return Value

true if s was converted successfully; otherwise, false. This operation returns false if the s parameter is a null reference (Nothing in Visual Basic), has an invalid format,represents a time interval less than MinValue or greater than MaxValue, or has at least one days, hours, minutes, or seconds component outside its valid range.

The TryParse method is like the TimeSpan.Parse method, except the TryParse method does not throw an exception if the conversion fails.

The s parameter contains a time interval specification of the form:

[ws][-]{ d | d.hh:mm[:ss[.ff]] | hh:mm[:ss[.ff]] }[ws]

Items in square brackets ([ and ]) are optional. One selection from the list of alternatives enclosed in braces ({ and }) and separated by vertical bars (|) is required. Colons and periods (: and .) are literal characters and required. Other items are as follows.

Item

Description

ws

Optional white space.

"-"

Optional minus sign indicating a negative TimeSpan.

d

Days, ranging from 0 to 10675199.

hh

Hours, ranging from 0 to 23.

mm

Minutes, ranging from 0 to 59.

ss

Optional seconds, ranging from 0 to 59.

ff

Optional fractional seconds, consisting of 1 to 7 decimal digits.

The components of s must collectively specify a time interval greater than or equal to MinValue and less than or equal to MaxValue.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.