如何在 C# 中将时间 UUID 转换为日期时间戳

Kha*_*anS 5 c# uuid cassandra timeuuid

我有一个TimeUuid需要将其转换为DateTime.

有没有办法在 C# 中做到这一点?

我正在使用DataStax 中的 CassandraCsharpDriver,但它不具备将 转换TimeUuid为 的功能Datetime,但相反的情况也是可能的。

示例 UUID:d91027c5-bd42-11e6-90be-2b4914b28d57

jor*_*ebg 4

您可以使用该结构GetDate()方法,该方法返回值的表示形式。TimeUuidDateTimeOffset

TimeUuid uuidValue = row.GetValue<TimeUuid>("time");
// TimeUuid structure exposes GetDate() method
DateTimeOffset dateOffset = uuidValue.GetDate();
DateTime dateTime = dateOffset.DateTime;
Run Code Online (Sandbox Code Playgroud)