c# - 将纳秒转换为日期时间

标签 c# datetime google-fit google-fit-sdk

我在将纳秒转换为 DateTime 时遇到了一点问题,因此我可以使用 Google Fit API ( https://developers.google.com/fit/rest/v1/reference/users/dataSources/datasets/get)

Dataset identifier that is a composite of the minimum data point start time and maximum data point end time represented as nanoseconds from the epoch. The ID is formatted like: "startTime-endTime" where startTime and endTime are 64 bit integers.

我能够通过这种方式将日期时间转换为纳秒

DateTime zuluTime = ssDatetime.ToUniversalTime();
DateTime unixEpoch = new DateTime(1970, 1, 1);
ssNanoSeconds = (Int32)(zuluTime.Subtract(unixEpoch)).TotalSeconds + "000000000";

但现在我需要将纳秒转换为 DateTime。我该怎么做?

最佳答案

使用AddTicks方法。不要忘记将纳秒除以 100 以获得滴答声。

long nanoseconds = 1449491983090000000;
DateTime epochTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime result = epochTime.AddTicks(nanoseconds / 100);

关于c# - 将纳秒转换为日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34133213/

相关文章:

json - Google fit API 根据范围添加多种数据类型

c# - TFS API 将多个测试点和结果添加到一次测试运行中

c# - 使用 ServerCertificateValidationCallback 的最佳实践

c# - 使用 DateTime 格式化问题日期

mysql - 计算同一表上的行之间的日期时间行差异

java - 从 Google Fit API 获取数据时不显示瞬时读数

c# - 将 C# 中命令行的输入流从 "Csvmidi.exe file.text file.midi"更改为 "Csvmidi.exe inputString file.midi"

c# - 命名空间命名约定

mysql - 日期时间值不正确 : '2014-10-19 00:00:00' for column time at row 2300

java - Android donut chart 根据时间戳填充多种颜色