Table of Contents

Struct UnixTime

Namespace
NanoByte.Common
Assembly
NanoByte.Common.dll

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

Seconds long

The 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

other UnixTime

An 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 other in the sort order. Zero This instance occurs in the same position in the sort order as other. Greater than zero This instance follows other in 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

info SerializationInfo

The System.Runtime.Serialization.SerializationInfo to populate with data.

context StreamingContext

The 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

timestamp UnixTime

Returns

DateTime

implicit operator DateTimeOffset(UnixTime)

Converts a Unix timestamp to a System.DateTimeOffset.

public static implicit operator DateTimeOffset(UnixTime timestamp)

Parameters

timestamp UnixTime

Returns

DateTimeOffset

implicit operator long(UnixTime)

Converts a Unix timestamp to a number of seconds.

public static implicit operator long(UnixTime timestamp)

Parameters

timestamp UnixTime

Returns

long

implicit operator UnixTime(DateTime)

Converts a dateTime to a Unix timestamp.

public static implicit operator UnixTime(DateTime dateTime)

Parameters

dateTime DateTime

Returns

UnixTime

implicit operator UnixTime(DateTimeOffset)

Converts a number of dateTime to a Unix timestamp.

public static implicit operator UnixTime(DateTimeOffset dateTime)

Parameters

dateTime DateTimeOffset

Returns

UnixTime

implicit operator UnixTime(long)

Converts a number of seconds to a Unix timestamp.

public static implicit operator UnixTime(long seconds)

Parameters

seconds long

Returns

UnixTime