AFTimeSpan.TryParse Method (String, IFormatProvider, AFTimeZone, AFTimeSpan)
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
Namespace: OSIsoft.AF.Time
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public static bool TryParse( string input, IFormatProvider provider, AFTimeZone timeZone, out AFTimeSpan result )
Public Shared Function TryParse ( input As String, provider As IFormatProvider, timeZone As AFTimeZone, <OutAttribute> ByRef result As AFTimeSpan ) As Boolean Dim input As String Dim provider As IFormatProvider Dim timeZone As AFTimeZone Dim result As AFTimeSpan Dim returnValue As Boolean returnValue = AFTimeSpan.TryParse(input, provider, timeZone, result)
public: static bool TryParse( String^ input, IFormatProvider^ provider, AFTimeZone^ timeZone, [OutAttribute] AFTimeSpan% result )
static member TryParse : input : string * provider : IFormatProvider * timeZone : AFTimeZone * result : AFTimeSpan byref -> bool
Parameters
- input
- Type: SystemString
A string that specifies the time interval to convert. If or an empty string, then Zero is returned as the result. - provider
- Type: SystemIFormatProvider
An object that supplies culture-specific formatting information. If , then CurrentCulture will be used. - timeZone
- Type: OSIsoft.AF.TimeAFTimeZone
The AFTimeZone specifying the time zone to calculate the interval time definitions when using the GetEvenTimeIntervalDefinitions(AFTimeRange) method. - result
- Type: OSIsoft.AF.TimeAFTimeSpan
When this method returns, contains an object that represents the time interval specified by input, or Zero if the conversion failed.
Return Value
Type: BooleanReturns if input was converted successfully; otherwise, . This operation returns if the input parameter is or String.Empty, has an invalid format, or has at least one years, months, days, hours, minutes, or seconds component outside its valid range.
Remarks
This method is like the Parse Overload method, except that it does not throw an exception if the conversion fails.
The time interval specification is in one of the following forms:
[+|-]<number>[.<number>] <interval> { [+|-]<number>[.<number>] <interval> }*
or
[+|-]{ 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.
| Element | Description |
|---|---|
| <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. |
| 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.
| Name | Short Name | Fractions Allowed |
|---|---|---|
| millisecond(s) | ms | Yes |
| second(s) | s | Yes |
| minute(s) | m | Yes |
| hour(s) | h | Yes |
| day(s) | d | No |
| month(s) | mo | No |
| year(s) | y | No |
| week(s) | w | No |
| weekday(s) | wd | No |
| yearday(s) | yd | No |