Struct UnixTime
Represents a point in time as the number of seconds since the Unix epoch (Unix timestamp).
[Serializable]
public readonly record struct UnixTime
- Extension Methods
Constructors
UnixTime(long)
Represents a point in time as the number of seconds since the Unix epoch (Unix timestamp).
public UnixTime(long Seconds)
Parameters
SecondslongThe number of seconds since the Unix epoch (00:00:00 UTC on 1 January 1970).
Properties
Seconds
The number of seconds since the Unix epoch (00:00:00 UTC on 1 January 1970).
public long Seconds { get; init; }
Property Value
- long
Methods
CompareTo(UnixTime)
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(UnixTime other)
Parameters
otherUnixTimeAn 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 asother. Greater than zero This instance followsotherin the sort order.
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.
GetObjectData(SerializationInfo, StreamingContext)
Populates a System.Runtime.Serialization.SerializationInfo with the data needed to serialize the target object.
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoThe System.Runtime.Serialization.SerializationInfo to populate with data.
contextStreamingContextThe destination (see System.Runtime.Serialization.StreamingContext) for this serialization.
Exceptions
- SecurityException
The caller does not have the required permission.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Operators
implicit operator DateTime(UnixTime)
Converts a Unix timestamp to a System.DateTime.
public static implicit operator DateTime(UnixTime timestamp)
Parameters
timestampUnixTime
Returns
- DateTime
implicit operator DateTimeOffset(UnixTime)
Converts a Unix timestamp to a System.DateTimeOffset.
public static implicit operator DateTimeOffset(UnixTime timestamp)
Parameters
timestampUnixTime
Returns
- DateTimeOffset
implicit operator long(UnixTime)
Converts a Unix timestamp to a number of seconds.
public static implicit operator long(UnixTime timestamp)
Parameters
timestampUnixTime
Returns
- long
implicit operator UnixTime(DateTime)
Converts a dateTime to a Unix timestamp.
public static implicit operator UnixTime(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
implicit operator UnixTime(DateTimeOffset)
Converts a number of dateTime to a Unix timestamp.
public static implicit operator UnixTime(DateTimeOffset dateTime)
Parameters
dateTimeDateTimeOffset
Returns
implicit operator UnixTime(long)
Converts a number of seconds to a Unix timestamp.
public static implicit operator UnixTime(long seconds)
Parameters
secondslong