Click or drag to resize
OSIsoft, LLC

AFTimeSpanParse Method (String, IFormatProvider)

Converts the string representation of a time interval to its AFTimeSpan equivalent.

Namespace:  OSIsoft.AF.Time
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version:
public static AFTimeSpan Parse(
	string input,
	IFormatProvider provider = null


Type: SystemString
A string that specifies the time interval to convert.
provider (Optional)
Type: SystemIFormatProvider
An object that supplies culture-specific formatting information. If , then CurrentCulture will be used.

Return Value

Type: AFTimeSpan
A time interval that corresponds to input parameter. If input is or an empty string, then Zero is returned.
FormatExceptioninput is an invalid format.
OverflowException At least one of the years, months, days, hours, minutes, or seconds components is outside its valid range.

The time interval specification is in one of the following forms:

[+|-]<number>[.<number>] <interval> { [+|-]<number>[.<number>] <interval> }*


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

Elements in square brackets ([ and ]) are optional. Alternatives are separated by a vertical bar (|). A star (*) after a group enclosed in braces ({ and }) indicates that zero or more instances of the group is allowed. The '+' or '-' operators are optional and if not specified defaults to the '+' (e.g. '5h10m' is the same as '5h+10m'). If only a number is specified (e.g. '10'), then it would match the second form and be interpreted as the number of hours.

The following table describes each element.

<number> A number consisting of one or more digits.
<interval> The name, short name, or plural name of a standard interval. The table below defines the standard intervals.
+ An optional plus sign, which indicates a positive AFTimeSpan value.
- An optional minus sign, which indicates a negative AFTimeSpan value.
. A culture-sensitive symbol that separates seconds from fractions of a second. The invariant format uses a period (".") character.
hh Hours. If hours are omitted, then time separator must be specified before the minutes.
: A culture-sensitive time separator symbol. The invariant format uses a colon (":") character.
mm Optional minutes.
ss Optional seconds.
ff Optional fractional seconds.
Note Notes to Callers
Some formats with missing hours, minutes, and/or seconds that were supported by PI Time are not supported. For example "hh:mm" is supported, but "hh::ss", ":mm:ss", and "::s" are some formats that are not supported. The format must be supported by the DateTime.TryParse method.

This is a table of the standard intervals. Either the plural full name, non-plural full name, or short name can be used as the name of the interval. The 'Fractions Allowed' column indicates if a fractional value is allowed for the interval type.

NameShort NameFractions Allowed

Version Information


Supported in: 2.10.5, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6, 2.5, 2.4
See Also
Enabling Operational Intelligence