c# - 如何知道 Instagram 中图片的发布时间?

标签 c# json interface unix-timestamp

我正在尝试通过C#获取图片instagram的发布时间。
例如,我从服务器获取了下一个字符串(JSON):
{"created_time":"1447156299","text":".........}
现在几点了?

最佳答案

您可以按如下方式进行:

static DateTime ConvertFromUnixTimestamp(double timestamp){
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}

您必须将“1447156299”传递给double,然后您就可以做到这一点。

有关更多信息,请查看此 tutorial

编辑

// This is an example of a UNIX timestamp for the date/time 11-04-2005 09:25.
double timestamp = 1113211532;

// First make a System.DateTime equivalent to the UNIX Epoch.
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

// Add the number of seconds in UNIX timestamp to be converted.
dateTime = dateTime.AddSeconds(timestamp);

// The dateTime now contains the right date/time so to format the string,
// use the standard formatting methods of the DateTime object.
string printDate = dateTime.ToShortDateString() +" "+ dateTime.ToShortTimeString();

// Print the date and time
System.Console.WriteLine(printDate);

取自 this site

输出带有 1113211532 UNIX 时间戳

4/11/2005 9:25 AM

输出带有 1447156299 UNIX 时间戳

11/10/2015 11:51 AM

关于c# - 如何知道 Instagram 中图片的发布时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33638668/

相关文章:

json - 如何调用以 json 字符串形式传递的函数

json - 读/写本地 json 文件 swift 4

c# - COM接口(interface)指南

java - Spring Boot 管理接口(interface) Bean

c# - C# 中的类型推断有哪些优点和缺点?

c# - 选择其中列 1 = 1 且列 2 = MAX(列 2)

python - Django - 导入错误: cannot import name simplejson

Cocoa:ABPeoplePickerView - 如何在单击一个人时触发方法?

c# - 如果绑定(bind)不匹配,则将项目添加到 itemssource

c# - FromAsyncPattern 会处理不再使用的资源吗?