AFTime Structure
- Last UpdatedNov 18, 2025
- 13 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
[SerializableAttribute] public struct AFTime : IComparable, IComparable<AFTime>, IEquatable<AFTime>, IFormattable
<SerializableAttribute> Public Structure AFTime Implements IComparable, IComparable(Of AFTime), IEquatable(Of AFTime), IFormattable Dim instance As AFTime
[SerializableAttribute] public value class AFTime : IComparable, IComparable<AFTime>, IEquatable<AFTime>, IFormattable
[<SealedAttribute>] [<SerializableAttribute>] type AFTime = struct interface IComparable interface IComparable<AFTime> interface IEquatable<AFTime> interface IFormattable end
The AFTime type exposes the following members.
Constructors
| Name | Description | |
|---|---|---|
| AFTime(DateTime) |
Initializes a new instance of the AFTime structure to the specified DateTime.
| |
| AFTime(Double) |
Initializes a new instance of the AFTime structure to the specified number of
seconds since January 1, 1970.
| |
| AFTime(Int64) |
Initializes a new instance of the AFTime structure to the specified number of ticks.
| |
| AFTime(Object) |
Initializes a new instance of the AFTime structure to the specified value.
| |
| AFTime(String) |
Initializes a new instance of the AFTime structure to the specified string
representation of time.
| |
| AFTime(Object, AFTime) |
Initializes a new instance of the AFTime structure to the specified value
representation of time using the CurrentCulture
information and formatting style, providing a default if necessary.
| |
| AFTime(Object, IFormatProvider) |
Initializes a new instance of the AFTime structure to the specified value
representation of time using the specified culture-specific information and
formatting style.
| |
| AFTime(String, IFormatProvider) |
Initializes a new instance of the AFTime structure to the specified string
representation of time using the specified culture-specific formatting information.
| |
| AFTime(Object, AFTime, IFormatProvider) |
Initializes a new instance of the AFTime structure to the specified value
representation of time using the specified culture-specific information and
formatting style, providing a default if necessary.
|
Properties
| Name | Description | |
|---|---|---|
| IsEmpty |
Tests whether this time has not been initialized or is
DateTime.MinValue.
| |
| LocalTime |
Gets a DateTime object converted to local time.
| |
| Now |
Gets a AFTime object that is set to the current date and time on
this computer.
| |
| NowInWholeSeconds |
Gets a AFTime object that is set to the current date and time on
this computer with the fractional seconds truncated.
| |
| PITime | Obsolete.
Returns the time as a PI SDK PITime.
| |
| UtcSeconds |
Return the time as the number of seconds since January 1, 1970, UTC.
| |
| UtcTime |
Gets a DateTime object that is expressed in Coordinated Universal
Time (UTC).
|
Methods
| Name | Description | |
|---|---|---|
| CompareTo(Object) |
Compares this instance with a specified Object.
| |
| CompareTo(AFTime) |
Compares this instance with a specified AFTime.
| |
| ConvertString |
Converts an AFTime or AFTimeSpan input string to a different culture-specific
normalized string.
| |
| Equals(Object) |
Determines whether the specified Object is equal to the current object.
(Overrides ValueTypeEquals(Object).) | |
| Equals(AFTime) |
Indicates whether the current object is equal to another object of the same type.
| |
| Equals(AFTime, Double) |
Indicates whether the current object is equal to another object of the same type.
| |
| GetAbbreviatedName |
Gets the culture-specific abbreviated time name of the specified invariant time name based on the specified format provider.
| |
| GetHashCode |
Gets the hash code for this instance of the object which is suitable for use in hashing
algorithms and data structures like a hash table.
(Overrides ValueTypeGetHashCode.) | |
| GetName |
Gets the culture-specific full time name of the specified invariant time name based on the specified format provider.
| |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| Parse(String, IFormatProvider) |
Converts the specified string representation of a local date and time to its AFTime equivalent
by using the specified culture-specific formatting information.
| |
| Parse(String, AFTime, IFormatProvider) |
Converts the specified string representation of a local date and time to its AFTime equivalent
by using the specified reference time and culture-specific formatting information.
| |
| ToPIPrecision |
Rounds the AFTime object to the precision supported by the PIServer.
| |
| ToString |
Returns a String that represents the current object.
(Overrides ValueTypeToString.) | |
| ToString(IFormatProvider) |
Returns a String that represents the current object.
| |
| ToString(String, IFormatProvider) |
Returns a String that represents the current object.
| |
| TruncateToWholeSeconds |
Truncates the fractional seconds from the AFTime object.
| |
| TryParse(String, AFTime) |
Converts the specified string representation of a local date and time to its AFTime equivalent
by using the CurrentCulture and returns a value that indicates whether
the conversion succeeded.
| |
| TryParse(String, AFTime, AFTime) |
Converts the specified string representation of a local date and time to its AFTime equivalent
by using the specified reference time and returns a value that indicates whether the conversion succeeded.
| |
| TryParse(String, IFormatProvider, AFTime) |
Converts the specified string representation of a local date and time to its AFTime equivalent
by using the specified culture-specific formatting information and returns a value that indicates whether
the conversion succeeded.
| |
| TryParse(String, AFTime, IFormatProvider, AFTime) |
Converts the specified string representation of a local date and time to its AFTime equivalent
by using the specified reference time and culture-specific formatting information,
and returns a value that indicates whether the conversion succeeded.
|
Operators
| Name | Description | |
|---|---|---|
| Addition(AFTime, AFTimeSpan) | ||
| Addition(AFTime, TimeSpan) |
Adds a specified TimeSpan time interval to a specified AFTime,
yielding a new AFTime.
| |
| Equality |
The equality operator (==) compares its operands to determine if they are equal.
| |
| GreaterThan |
The greater than relation operator (>) compares its operands to determine
which one is greater than the other.
| |
| GreaterThanOrEqual |
The greater than or equal relation operator (>=) compares its operands to determine
which one is greater than or equal to the other.
| |
| (DateTime to AFTime) |
Implicit cast operator to convert a DateTime to an AFTime.
| |
| (AFTime to DateTime) |
Implicit cast operator to convert an AFTime to a DateTime.
| |
| Inequality |
The inequality operator (!=) compares its operands to determine if they are not equal.
| |
| LessThan |
The less than relation operator (<) compares its operands to determine
which one is less than the other.
| |
| LessThanOrEqual |
The less than or equal relation operator (<=) compares its operands to determine
which one is less than or equal to the other.
| |
| Subtraction(AFTime, AFTime) |
Subtracts a specified AFTime from another specified AFTime,
yielding a time interval.
| |
| Subtraction(AFTime, AFTimeSpan) | ||
| Subtraction(AFTime, TimeSpan) |
Subtracts a specified TimeSpan time interval from a specified AFTime,
yielding a new AFTime.
|
Fields
| Name | Description | |
|---|---|---|
| MaxValue |
Represents the largest possible value of AFTime.
| |
| MinValue |
Represents the smallest possible value of AFTime.
|
Remarks
Represents the date and time data ranging in value from January 1, 1970 to December 31, 9999. Internally, the time is represented as a System.DateTime in Coordinated Universal Time (UTC). Actual storage of an AFTime value may cause a loss of accuracy depending on the target storage. The PI AF Server will store timestamps to an accuracy of 100 nanoseconds which is the same as the .NET DateTime precision. A PI 3.x Server stores timestamps to an accuracy of 15 microseconds.
When converting to local time (see LocalTime), time zones containing multiple daylight saving time adjustment rules are taken into account. This allows accurate representation of times outside the daylight saving time adjustment rule for the current year.
For a description of the supported string representations that can be parsed as an AFTime, see the TryParse(String, AFTime) method.
Examples
// This example shows how to use the AFTime class // to convert between AFTime, PI Time strings, and common time strings. // Display current time in UtcSeconds Console.WriteLine("Now (in UtcSeconds) = {0}", AFTime.Now.UtcSeconds); // Create an AFTime from a PITime formatted string AFTime oneHourAgo = new AFTime("*-1h", CultureInfo.CurrentCulture); Console.WriteLine("One Hour Ago = {0}", oneHourAgo.LocalTime); // Create an AFTime without throwing an exception for an invalid string string input = "Y+4dd"; AFTime result; if (!AFTime.TryParse(input, out result)) Console.WriteLine("Input '{0}' was not valid.", input); else Console.WriteLine("Input '{0}' = {1}", input, result.LocalTime); // Create an AFTime from a date string AFTime y2k = new AFTime("1/1/2000 12:00:00 AM", CultureInfo.InvariantCulture); Console.WriteLine("Y2K, Locally = {0}", y2k.LocalTime);
' This example shows how to use the AFTime class ' to convert between AFTime, PI time strings, and common time strings. ' Display current time in UtcSeconds Console.WriteLine("Now (in UtcSeconds) = {0}", AFTime.Now.UtcSeconds) ' Create an AFTime from a PITime formatted string Dim oneHourAgo As AFTime = New OSIsoft.AF.Time.AFTime("*-1h", CultureInfo.CurrentCulture) Console.WriteLine("One Hour Ago = {0}", oneHourAgo.LocalTime) ' Create an AFTime without throwing an exception for an invalid string Dim input As String = "Y+4dd" Dim result As AFTime If Not AFTime.TryParse(input, result) Then Console.WriteLine("Input '{0}' was not valid.", input) Else Console.WriteLine("Input '{0}' = {1}", input, result.LocalTime) End If ' Create an AFTime from a date string Dim y2k As AFTime = New OSIsoft.AF.Time.AFTime("1/1/2000 12:00:00 AM", CultureInfo.InvariantCulture) Console.WriteLine("Y2K, Locally = {0}", y2k.LocalTime)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
// This example shows how to serialize an AFTime AFTime time = AFTime.Now; Console.WriteLine("Time = {0}", time.LocalTime); // Serialize using Json string parametersJson = JsonConvert.SerializeObject(time); AFTime restoredJsonTime = JsonConvert.DeserializeObject<AFTime>(parametersJson); Console.WriteLine("Restored Time from Json = {0}", restoredJsonTime.LocalTime); // Serialize using XmlSerializer AFTime restoredXmlTime; using (var stream = new MemoryStream()) { XmlSerializer serializer = new XmlSerializer(typeof(AFTime)); serializer.Serialize(stream, time); stream.Seek(0, SeekOrigin.Begin); restoredXmlTime = (AFTime)serializer.Deserialize(stream); } Console.WriteLine("Restored Time from XmlSerializer = {0}", restoredXmlTime.LocalTime);
' This example shows how to serialize an AFTime Dim time As AFTime = AFTime.Now Console.WriteLine("Time = {0}", time.LocalTime) ' Serialize using Json Dim parametersJson As String = JsonConvert.SerializeObject(time) Dim restoredJsonTime As AFTime = JsonConvert.DeserializeObject(Of AFTime)(parametersJson) Console.WriteLine("Restored Time from Json = {0}", restoredJsonTime.LocalTime) ' Serialize using XmlSerializer Dim restoredXmlTime As AFTime Using stream As MemoryStream = New MemoryStream() Dim serializer As New XmlSerializer(GetType(AFTime)) serializer.Serialize(stream, time) stream.Seek(0, SeekOrigin.Begin) restoredXmlTime = DirectCast(serializer.Deserialize(stream), AFTime) End Using Console.WriteLine("Restored Time from XmlSerializer = {0}", restoredXmlTime.LocalTime)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.