Skip to main content

ResQ.Protocols.ProtocolExtensions

ProtocolExtensions.FromUnixMs(this long) Method

Converts a Unix timestamp in milliseconds to a System.DateTimeOffset.
public static System.DateTimeOffset FromUnixMs(this long timestampMs);

Parameters

timestampMs System.Int64 The Unix timestamp in milliseconds since January 1, 1970 UTC.

Returns

System.DateTimeOffset
A System.DateTimeOffset representing the specified timestamp.

Example

// From a protobuf timestamp field
long timestampMs = 1704067200000; // 2024-01-01 00:00:00 UTC
var dateTime = timestampMs.FromUnixMs();
Console.WriteLine(dateTime); // 2024-01-01 00:00:00 +00:00

// From current time
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().FromUnixMs();

Remarks

This method handles the conversion from Unix time (common in protobuf and JSON APIs) to .NET’s System.DateTimeOffset type. The resulting value has UTC as its offset.