Skip to content

TimeUtility

Namespace: SideXP.Core

public static class TimeUtility

Miscellaneous functions for working with time and date values.

Methods

GetTimestamp(bool)

public static long GetTimestamp(bool local = false)

Gets the number of milliseconds elapsed since the Unix epoch (1970-01-01 UTC) for the current time.

Parameters

  • local: If enabled, computes the timestamp from local wall-clock time (Now) instead of UTC (UtcNow).

Returns

Returns the number of elapsed milliseconds.

GetTimestampSeconds(bool)

public static long GetTimestampSeconds(bool local = false)

Gets the number of seconds elapsed since the Unix epoch (1970-01-01 UTC) for the current time.

Parameters

  • local: If enabled, computes the timestamp from local wall-clock time (Now) instead of UTC (UtcNow).

Returns

Returns the number of elapsed seconds.

ToTimestamp(DateTime)

public static long ToTimestamp(DateTime time)

Converts a given time into the number of elapsed milliseconds since the Unix epoch (1970-01-01 UTC). The DateTime's wall-clock value is used as-is (its DateTimeKind is not normalized), so pass a UTC value (e.g. UtcNow) for a true Unix timestamp.

Parameters

  • time: The time to convert.

Returns

Returns the number of elapsed milliseconds.

ToTimestampSeconds(DateTime)

public static long ToTimestampSeconds(DateTime time)

Converts a given time into the number of elapsed seconds since the Unix epoch (1970-01-01 UTC).

Parameters

  • time: The time to convert.

Returns

Returns the number of elapsed seconds.