Struct Time
public readonly struct Time : IComparable, IComparable<Time>, IEquatable<Time>, ISpanFormattable, IFormattable, IComparisonOperators<Time, Time, bool>, IEqualityOperators<Time, Time, bool>
- Implements
- Inherited Members
Constructors
Time(long)
public Time(long nanosecondsSinceUnixEpoch)
Parameters
nanosecondsSinceUnixEpochlong
Fields
MicrosecondsPerSecond
public const long MicrosecondsPerSecond = 1000000
Field Value
MillisecondsPerSecond
public const long MillisecondsPerSecond = 1000
Field Value
NanosecondsPerMicrosecond
public const long NanosecondsPerMicrosecond = 1000
Field Value
NanosecondsPerMillisecond
public const long NanosecondsPerMillisecond = 1000000
Field Value
NanosecondsPerSecond
public const long NanosecondsPerSecond = 1000000000
Field Value
Properties
NanosecondsSinceUnixEpoch
public long NanosecondsSinceUnixEpoch { get; }
Property Value
Methods
CompareTo(Time)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(Time other)
Parameters
otherTimeAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
CompareTo(object?)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(object? obj)
Parameters
objobjectAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes objin the sort order.Zero This instance occurs in the same position in the sort order as obj.Greater than zero This instance follows objin the sort order.
Exceptions
- ArgumentException
objis not the same type as this instance.
Equals(Time)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Time other)
Parameters
otherTimeAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
FromPosixTime(long, long)
public static Time FromPosixTime(long seconds, long nanoseconds)
Parameters
Returns
FromWindowsFileTime(long)
public static Time FromWindowsFileTime(long fileTime)
Parameters
fileTimelong
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
MicrosecondsToNanoseconds(long)
public static long MicrosecondsToNanoseconds(long microseconds)
Parameters
microsecondslong
Returns
MillisecondsToNanoseconds(long)
public static long MillisecondsToNanoseconds(long milliseconds)
Parameters
millisecondslong
Returns
NanosecondsToSeconds(long)
public static (long seconds, int milliseconds, int microseconds, int nanoseconds) NanosecondsToSeconds(long nanoseconds)
Parameters
nanosecondslong
Returns
NanosecondsToWholeMicroseconds(long)
public static long NanosecondsToWholeMicroseconds(long nanoseconds)
Parameters
nanosecondslong
Returns
NanosecondsToWholeMilliseconds(long)
public static long NanosecondsToWholeMilliseconds(long nanoseconds)
Parameters
nanosecondslong
Returns
NanosecondsToWholeSeconds(long)
public static long NanosecondsToWholeSeconds(long nanoseconds)
Parameters
nanosecondslong
Returns
SecondsToNanoseconds(long)
public static long SecondsToNanoseconds(long seconds)
Parameters
secondslong
Returns
ToPosixTime()
public (long seconds, long nanoseconds) ToPosixTime()
Returns
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
ToString(IFormatProvider?)
public string ToString(IFormatProvider? formatProvider)
Parameters
formatProviderIFormatProvider
Returns
ToString(string?)
public string ToString(string? format)
Parameters
formatstring
Returns
ToString(string?, IFormatProvider?)
Formats the value of the current instance using the specified format.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format to use.
-or-
A null reference (
Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (
Nothingin Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
Returns
- string
The value of the current instance in the specified format.
ToWindowFileTime()
public long ToWindowFileTime()
Returns
TryConvertFromDateTime(in DateTime, out Time)
public static bool TryConvertFromDateTime(in DateTime dateTime, out Time time)
Parameters
Returns
TryConvertToDateTime(out DateTime, bool)
public bool TryConvertToDateTime(out DateTime dateTime, bool convertToLocalTime = true)
Parameters
Returns
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance into the provided span of characters.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
Parameters
destinationSpan<char>The span in which to write this instance's value formatted as a span of characters.
charsWrittenintWhen this method returns, contains the number of characters that were written in
destination.formatReadOnlySpan<char>A span containing the characters that represent a standard or custom format string that defines the acceptable format for
destination.providerIFormatProviderAn optional object that supplies culture-specific formatting information for
destination.
Returns
TryGetCurrentTime(out Time)
public static bool TryGetCurrentTime(out Time time)
Parameters
timeTime
Returns
Operators
operator ==(Time, Time)
Compares two values to determine equality.
public static bool operator ==(Time left, Time right)
Parameters
Returns
operator >(Time, Time)
Compares two values to determine which is greater.
public static bool operator >(Time left, Time right)
Parameters
Returns
operator >=(Time, Time)
Compares two values to determine which is greater or equal.
public static bool operator >=(Time left, Time right)
Parameters
Returns
operator !=(Time, Time)
Compares two values to determine inequality.
public static bool operator !=(Time left, Time right)
Parameters
Returns
operator <(Time, Time)
Compares two values to determine which is less.
public static bool operator <(Time left, Time right)
Parameters
Returns
operator <=(Time, Time)
Compares two values to determine which is less or equal.
public static bool operator <=(Time left, Time right)