Click or drag to resize
OSIsoft, LLC

AFTime Structure

AFTime is used to represent time and convert between various time formats.

Namespace:  OSIsoft.AF.Time
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 2.10.6.195
Syntax
[SerializableAttribute]
public struct AFTime : IComparable, IComparable<AFTime>, 
	IEquatable<AFTime>, IFormattable

The AFTime type exposes the following members.

Constructors
  NameDescription
Public methodAFTime(DateTime)
Initializes a new instance of the AFTime structure to the specified DateTime.
Public methodAFTime(Double)
Initializes a new instance of the AFTime structure to the specified number of seconds since January 1, 1970.
Public methodAFTime(Int64)
Initializes a new instance of the AFTime structure to the specified number of ticks.
Public methodAFTime(Object)
Initializes a new instance of the AFTime structure to the specified value.
Public methodCode exampleAFTime(String)
Initializes a new instance of the AFTime structure to the specified string representation of time.
Public methodAFTime(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.
Public methodAFTime(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.
Public methodCode exampleAFTime(String, IFormatProvider)
Initializes a new instance of the AFTime structure to the specified string representation of time using the specified culture-specific formatting information.
Public methodAFTime(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.
Top
Properties
  NameDescription
Public propertyIsEmpty
Tests whether this time has not been initialized or is DateTime.MinValue.
Public propertyLocalTime
Gets a DateTime object converted to local time.
Public propertyStatic memberNow
Gets a AFTime object that is set to the current date and time on this computer.
Public propertyStatic memberNowInWholeSeconds
Gets a AFTime object that is set to the current date and time on this computer with the fractional seconds truncated.
Public propertyPITime Obsolete.
Returns the time as a PI SDK PITime.
Public propertyUtcSeconds
Return the time as the number of seconds since January 1, 1970, UTC.
Public propertyUtcTime
Gets a DateTime object that is expressed in Coordinated Universal Time (UTC).
Top
Methods
  NameDescription
Public methodCompareTo(Object)
Compares this instance with a specified Object.
Public methodCompareTo(AFTime)
Compares this instance with a specified AFTime.
Public methodStatic memberConvertString
Converts an AFTime or AFTimeSpan input string to a different culture-specific normalized string.
Public methodEquals(Object)
Determines whether the specified Object is equal to the current object.
(Overrides ValueTypeEquals(Object).)
Public methodEquals(AFTime)
Indicates whether the current object is equal to another object of the same type.
Public methodEquals(AFTime, Double)
Indicates whether the current object is equal to another object of the same type.
Public methodStatic memberGetAbbreviatedName
Gets the culture-specific abbreviated time name of the specified invariant time name based on the specified format provider.
Public methodGetHashCode
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.)
Public methodStatic memberGetName
Gets the culture-specific full time name of the specified invariant time name based on the specified format provider.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberParse(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.
Public methodStatic memberParse(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.
Public methodToPIPrecision
Rounds the AFTime object to the precision supported by the PIServer.
Public methodToString
Returns a String that represents the current object.
(Overrides ValueTypeToString.)
Public methodToString(IFormatProvider)
Returns a String that represents the current object.
Public methodToString(String, IFormatProvider)
Returns a String that represents the current object.
Public methodTruncateToWholeSeconds
Truncates the fractional seconds from the AFTime object.
Public methodStatic memberCode exampleTryParse(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.
Public methodStatic memberCode exampleTryParse(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.
Public methodStatic memberCode exampleTryParse(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.
Public methodStatic memberCode exampleTryParse(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.
Top
Operators
  NameDescription
Public operatorStatic memberAddition(AFTime, AFTimeSpan)
Adds a specified AFTimeSpan time interval to a specified AFTime, yielding a new AFTime.
Public operatorStatic memberAddition(AFTime, TimeSpan)
Adds a specified TimeSpan time interval to a specified AFTime, yielding a new AFTime.
Public operatorStatic memberEquality
The equality operator (==) compares its operands to determine if they are equal.
Public operatorStatic memberGreaterThan
The greater than relation operator (>) compares its operands to determine which one is greater than the other.
Public operatorStatic memberGreaterThanOrEqual
The greater than or equal relation operator (>=) compares its operands to determine which one is greater than or equal to the other.
Public operatorStatic member(DateTime to AFTime)
Implicit cast operator to convert a DateTime to an AFTime.
Public operatorStatic member(AFTime to DateTime)
Implicit cast operator to convert an AFTime to a DateTime.
Public operatorStatic memberInequality
The inequality operator (!=) compares its operands to determine if they are not equal.
Public operatorStatic memberLessThan
The less than relation operator (<) compares its operands to determine which one is less than the other.
Public operatorStatic memberLessThanOrEqual
The less than or equal relation operator (<=) compares its operands to determine which one is less than or equal to the other.
Public operatorStatic memberSubtraction(AFTime, AFTime)
Subtracts a specified AFTime from another specified AFTime, yielding a time interval.
Public operatorStatic memberSubtraction(AFTime, AFTimeSpan)
Subtracts a specified AFTimeSpan time interval from a specified AFTime, yielding a new AFTime.
Public operatorStatic memberSubtraction(AFTime, TimeSpan)
Subtracts a specified TimeSpan time interval from a specified AFTime, yielding a new AFTime.
Top
Fields
  NameDescription
Public fieldStatic memberMaxValue
Represents the largest possible value of AFTime.
Public fieldStatic memberMinValue
Represents the smallest possible value of AFTime.
Top
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, strings, and PITimeServer.PITime.

// Create a PITime from an AFTime
PITimeServer.PITime piTimeNow = (PITimeServer.PITime)AFTime.Now.PITime;

// Create an AFTime from a PITime
AFTime now = new AFTime(piTimeNow, CultureInfo.CurrentCulture);
Console.WriteLine("Now = {0}", now.LocalTime);

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

// Serialize using BinaryFormatter
AFTime restoredBinaryTime;
using (var stream = new MemoryStream())
{
    var serializer = new BinaryFormatter();
    serializer.Serialize(stream, time);
    stream.Seek(0, SeekOrigin.Begin);
    restoredBinaryTime = (AFTime)serializer.Deserialize(stream);
}
Console.WriteLine("Restored Time from XmlSerializer = {0}", restoredBinaryTime.LocalTime);
Version Information

AFSDK

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