如何从 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/