c# - 如何从 StackOverflow API *creation_date* 字段中检索实际日期?

标签 c# stackexchange-api

如何从 StackOverflow API creation_date 字段中检索实际日期?

通过 their API 描述的日期是一个整数:

"creation_date": 1288523078

但是,我想将整数转换为实际的 DateTime 值。

我看到了这个link .但我还是不清楚。

最佳答案

docs 中所述:

All dates in the API are in unix epoch time, which is the number of seconds since midnight UTC January 1st, 1970

要转换为 .NET 日期时间,请执行以下操作:

int apiDate = 1288523078;
// `date` is UTC date here, if you need it in local timezone
//  call ToLocalTime() at the end
var date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(apiDate);

关于c# - 如何从 StackOverflow API *creation_date* 字段中检索实际日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47550717/

相关文章:

c# - 检查实例是否正确实例化的最佳方法

c# - 我将 ServiceBusTriggerAttribute fork 为 public 并删除了 seal - 出现异常

C# - 将列表框项目 move 到新的列表框

stackexchange-api - 用户的 Stack Overflow 时间线(提要)

c# winforms 如何旋转图像(但不围绕其中心旋转)

c# - Word Interop - 如何确定 Word 文档的页眉/页脚中是否有页码

perl - 如何从 perl 脚本访问 StackExchange API 验证方法?

emacs - Emacs 中 SE 的 OAuth 工作流程

java - 如何获取答案的内容?